/** * Return the generated form output. * @return Form HTML. */ public static function get_form($args, $node) { define("MODE_GRID", 0); define("MODE_NEW_SAMPLE", 1); define("MODE_EXISTING", 2); self::parse_defaults($args); self::getArgDefaults($args); self::$node = $node; // if we use locks, we want them to be distinct for each drupal user if (function_exists('profile_load_profile')) { // check we are in drupal global $user; data_entry_helper::$javascript .= "if (indicia && indicia.locks && indicia.locks.setUser) {\n indicia.locks.setUser ('" . $user->uid . "');\n }\n"; } // hard-wire some 'dynamic' options to simplify the form. Todo: take out the dynamic code for these $args['subjectAccordion'] = false; $args['emailShow'] = false; $args['nameShow'] = false; $args['copyFromProfile'] = false; $args['multiple_subject_observation_mode'] = 'single'; $args['extra_list_id'] = ''; $args['occurrence_comment'] = false; $args['col_widths'] = ''; $args['includeLocTools'] = false; $args['loctoolsLocTypeID'] = 0; $args['subject_observation_confidential'] = false; $args['observation_images'] = false; // Get authorisation tokens to update and read from the Warehouse. $auth = data_entry_helper::get_read_write_auth($args['website_id'], $args['password']); $svcUrl = self::warehouseUrl() . 'index.php/services'; self::$auth = $auth; drupal_add_js(iform_media_folder_path() . 'js/jquery.form.js', 'module'); $mode = isset($args['no_grid']) && $args['no_grid'] ? MODE_NEW_SAMPLE : MODE_GRID; // default mode when no grid set to false - display grid of existing data // mode MODE_EXISTING: display existing sample $loadedSampleId = null; $loadedSubjectObservationId = null; 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 (function_exists('iform_loctools_checkaccess') && iform_loctools_checkaccess($node, 'admin') && array_key_exists('mnhnld1', $_POST)) { iform_loctools_deletelocations($node); foreach ($_POST as $key => $value) { $parts = explode(':', $key); iform_loctools_insertlocation($node, $parts[2], $parts[1]); } } } else { if (!is_null(data_entry_helper::$entity_to_load)) { $mode = MODE_EXISTING; // errors with new sample, entity populated with post, so display this data. } } // else valid save, so go back to gridview: default mode 0 } if (array_key_exists('sample_id', $_GET) && $_GET['sample_id'] != '{sample_id}') { $mode = MODE_EXISTING; $loadedSampleId = $_GET['sample_id']; } if (array_key_exists('subject_observation_id', $_GET) && $_GET['subject_observation_id'] != '{subject_observation_id}') { $mode = MODE_EXISTING; // single subject_observation case $loadedSubjectObservationId = $_GET['subject_observation_id']; self::$subjectObservationIds = array($loadedSubjectObservationId); } if ($mode != MODE_EXISTING && array_key_exists('newSample', $_GET)) { $mode = MODE_NEW_SAMPLE; data_entry_helper::$entity_to_load = array(); } // else default to mode MODE_GRID or MODE_NEW_SAMPLE depending on no_grid parameter self::$mode = $mode; // default mode MODE_GRID : display grid of the samples to add a new one // or edit an existing one. if ($mode == MODE_GRID) { $r = ''; // debug section if (!empty($args['debug_info']) && $args['debug_info']) { $r .= '<input type="button" value="Debug info" onclick="$(\'#debug-info-div\').slideToggle();" /><br />' . '<div id="debug-info-div" style="display: none;">'; $r .= '<p>$_GET is:<br /><pre>' . print_r($_GET, true) . '</pre></p>'; $r .= '<p>$_POST is:<br /><pre>' . print_r($_POST, true) . '</pre></p>'; $r .= '<p>Entity to load is:<br /><pre>' . print_r(data_entry_helper::$entity_to_load, true) . '</pre></p>'; $r .= '<p>Submission was:<br /><pre>' . print_r(self::$submission, true) . '</pre></p>'; $r .= '<input type="button" value="Hide debug info" onclick="$(\'#debug-info-div\').slideToggle();" />'; $r .= '</div>'; } if (method_exists(get_called_class(), 'getHeaderHTML')) { $r .= call_user_func(array(get_called_class(), 'getHeaderHTML'), true, $args); } $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']), false); $tabs = array('#sampleList' => lang::get('LANG_Main_Samples_Tab')); if ($args['includeLocTools'] && function_exists('iform_loctools_checkaccess') && iform_loctools_checkaccess($node, 'admin')) { $tabs['#setLocations'] = lang::get('LANG_Allocate_Locations'); } if (method_exists(get_called_class(), 'getExtraGridModeTabs')) { $extraTabs = call_user_func(array(get_called_class(), 'getExtraGridModeTabs'), false, $auth['read'], $args, $attributes); if (is_array($extraTabs)) { $tabs = $tabs + $extraTabs; } } if (count($tabs) > 1) { $r .= "<div id=\"controls\">" . data_entry_helper::enable_tabs(array('divId' => 'controls', 'active' => '#sampleList')) . "<div id=\"temp\"></div>"; $r .= data_entry_helper::tab_header(array('tabs' => $tabs)); } $r .= "<div id=\"sampleList\">" . call_user_func(array(get_called_class(), 'getSampleListGrid'), $args, $node, $auth, $attributes) . "</div>"; if ($args['includeLocTools'] && function_exists('iform_loctools_checkaccess') && iform_loctools_checkaccess($node, 'admin')) { $r .= ' <div id="setLocations"> <form method="post"> <input type="hidden" id="mnhnld1" name="mnhnld1" value="mnhnld1" /><table border="1"><tr><td></td>'; $url = $svcUrl . '/data/location?mode=json&view=detail&auth_token=' . $auth['read']['auth_token'] . "&nonce=" . $auth['read']["nonce"] . "&parent_id=NULL&orderby=name" . (isset($args['loctoolsLocTypeID']) && $args['loctoolsLocTypeID'] != '' ? '&location_type_id=' . $args['loctoolsLocTypeID'] : ''); $session = curl_init($url); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); $entities = json_decode(curl_exec($session), true); $userlist = iform_loctools_listusers($node); foreach ($userlist as $uid => $a_user) { $r .= '<td>' . $a_user->name . '</td>'; } $r .= "</tr>"; if (!empty($entities)) { foreach ($entities as $entity) { if (!$entity["parent_id"]) { // only assign parent locations. $r .= "<tr><td>" . $entity["name"] . "</td>"; $defaultuserids = iform_loctools_getusers($node, $entity["id"]); foreach ($userlist as $uid => $a_user) { $r .= '<td><input type="checkbox" name="location:' . $entity["id"] . ':' . $uid . (in_array($uid, $defaultuserids) ? '" checked="checked"' : '"') . '></td>'; } $r .= "</tr>"; } } } $r .= "</table>\n <input type=\"submit\" class=\"ui-state-default ui-corner-all\" value=\"" . lang::get('LANG_Save_Location_Allocations') . "\" />\n </form>\n </div>"; } if (method_exists(get_called_class(), 'getExtraGridModeTabs')) { $r .= call_user_func(array(get_called_class(), 'getExtraGridModeTabs'), true, $auth['read'], $args, $attributes); } 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'), true, $args); } return $r; } // from this point on, we are MODE_EXISTING or MODE_NEW_SAMPLE if ($mode == MODE_EXISTING && is_null(data_entry_helper::$entity_to_load)) { // only load if not in error situation // Displaying an existing sample. If we know the subject_observation ID, and don't know the sample ID // then we must get the sample id from the subject_observation data. if ($loadedSubjectObservationId && !$loadedSampleId) { data_entry_helper::load_existing_record($auth['read'], 'subject_observation', $loadedSubjectObservationId); $loadedSampleId = data_entry_helper::$entity_to_load['subject_observation:sample_id']; } data_entry_helper::$entity_to_load = self::reload_form_data($loadedSampleId, $args, $auth); } // get the sample attributes $attrOpts = array('id' => data_entry_helper::$entity_to_load['sample:id'], 'valuetable' => 'sample_attribute_value', 'attrtable' => 'sample_attribute', 'key' => 'sample_id', 'fieldprefix' => 'smpAttr', 'extraParams' => $auth['read'], 'survey_id' => $args['survey_id']); // select only the custom attributes that are for this sample method or all sample methods, if this // form is for a specific sample method. if (!empty($args['sample_method_id'])) { $attrOpts['sample_method_id'] = $args['sample_method_id']; } $attributes = data_entry_helper::getAttributes($attrOpts, false); // Check if Recorder details is included as a control. // If so, remove the recorder attributes from the $attributes array so not output anywhere else. $arr = helper_base::explode_lines($args['structure']); if (in_array('[recorder details]', $arr)) { $attrCount = count($attributes); for ($i = 0; $i < $attrCount; $i++) { if (strcasecmp($attributes[$i]['caption'], 'first name') === 0 || strcasecmp($attributes[$i]['caption'], 'last name') === 0 || strcasecmp($attributes[$i]['caption'], 'email') === 0) { unset($attributes[$i]); } } } //// Make sure the form action points back to this page $reload = data_entry_helper::get_reload_link_parts(); unset($reload['params']['sample_id']); unset($reload['params']['subject_observation_id']); unset($reload['params']['newSample']); $reloadPath = $reload['path']; // don't url-encode the drupal path id using dirty url $pathParam = function_exists('variable_get') && variable_get('clean_url', 0) == '0' ? 'q' : ''; if (count($reload['params'])) { if ($pathParam === 'q' && array_key_exists('q', $reload['params'])) { $reloadPath .= '?q=' . $reload['params']['q']; unset($reload['params']['q']); if (count($reload['params'])) { $reloadPath .= '&' . http_build_query($reload['params']); } } else { $reloadPath .= '?' . http_build_query($reload['params']); } } $r = "<form method=\"post\" id=\"entry_form\" action=\"{$reloadPath}\">\n"; // debug section if (!empty($args['debug_info']) && $args['debug_info']) { $r .= '<input type="button" value="Debug info" onclick="$(\'#debug-info-div\').slideToggle();" /><br />' . '<div id="debug-info-div" style="display: none;">'; $r .= '<p>$_GET is:<br /><pre>' . print_r($_GET, true) . '</pre></p>'; $r .= '<p>$_POST is:<br /><pre>' . print_r($_POST, true) . '</pre></p>'; $r .= '<p>Entity to load is:<br /><pre>' . print_r(data_entry_helper::$entity_to_load, true) . '</pre></p>'; $r .= '<p>Submission was:<br /><pre>' . print_r(self::$submission, true) . '</pre></p>'; $r .= '<input type="button" value="Hide debug info" onclick="$(\'#debug-info-div\').slideToggle();" />'; $r .= '</div>'; } // reset button $r .= '<input type="button" class="ui-state-default ui-corner-all" value="' . lang::get('Abandon Form and Reload') . '" ' . 'onclick="window.location.href=\'' . url('node/' . $node->nid, array('query' => 'newSample')) . '\'">'; // clear all padlocks button $r .= ' <input type="button" class="ui-state-default ui-corner-all" value="' . lang::get('Clear All Padlocks') . '" ' . 'onclick="if (indicia && indicia.locks) indicia.locks.unlockRegion(\'body\');">'; // Get authorisation tokens to update the Warehouse, plus any other hidden data. $hiddens = $auth['write'] . "<input type=\"hidden\" id=\"read_auth_token\" name=\"read_auth_token\" value=\"" . $auth['read']['auth_token'] . "\" />\n" . "<input type=\"hidden\" id=\"read_nonce\" name=\"read_nonce\" value=\"" . $auth['read']['nonce'] . "\" />\n" . "<input type=\"hidden\" id=\"website_id\" name=\"website_id\" value=\"" . $args['website_id'] . "\" />\n" . "<input type=\"hidden\" id=\"survey_id\" name=\"survey_id\" value=\"" . $args['survey_id'] . "\" />\n"; if (!empty($args['sample_method_id'])) { $hiddens .= '<input type="hidden" name="sample:sample_method_id" value="' . $args['sample_method_id'] . '"/>'; } if (isset(data_entry_helper::$entity_to_load['sample:id'])) { $hiddens .= "<input type=\"hidden\" id=\"sample:id\" name=\"sample:id\" value=\"" . data_entry_helper::$entity_to_load['sample:id'] . "\" />\n"; } // request automatic JS validation if (!isset($args['clientSideValidation']) || $args['clientSideValidation']) { data_entry_helper::enable_validation('entry_form'); // override the default invalidHandler to activate the first accordion panels which has an error global $indicia_templates; $indicia_templates['invalid_handler_javascript'] = "function(form, validator) {\n var tabselected=false;\n var accordion\$=jQuery('.ui-accordion');\n jQuery.each(validator.errorMap, function(ctrlId, error) {\n // select the tab containing the first error control\n var ctrl = jQuery('[name=' + ctrlId.replace(/:/g, '\\\\:').replace(/\\[/g, '\\\\[').replace(/]/g, '\\\\]') + ']');\n if (!tabselected && typeof(tabs)!=='undefined') {\n tabs.tabs('select',ctrl.filter('input,select').parents('.ui-tabs-panel')[0].id);\n tabselected = true;\n }\n ctrl.parents('fieldset').removeClass('collapsed');\n ctrl.parents('.fieldset-wrapper').show();\n // for each accordion, activate the first panel which has an error\n ctrl.parents('.ui-accordion-content').each(function (n) {\n var acc\$ = \$(this).closest('.ui-accordion');\n var accId = acc\$[0].id.replace(/:/g, '\\\\:').replace(/\\[/g, '\\\\[').replace(/]/g, '\\\\]');\n if (accordion\$.is('#'+accId)) {\n var header\$ = \$(this).prev('h3');\n var accHeaderId = header\$.attr('id').replace(/:/g, '\\\\:').replace(/\\[/g, '\\\\[').replace(/]/g, '\\\\]');\n acc\$.accordion('activate', '#'+accHeaderId);\n accordion\$ = accordion\$.not('#'+accId);\n }\n });\n });\n }"; // By default, validate doesn't validate any ':hidden' fields, // but we need to validate hidden with display: none; fields in accordions data_entry_helper::$javascript .= "jQuery.validator.setDefaults({ \n ignore: \"input[type='hidden']\"\n });\n"; } if (method_exists(get_called_class(), 'getHeaderHTML')) { $r .= call_user_func(array(get_called_class(), 'getHeaderHTML'), true, $args); } if ($mode == MODE_EXISTING && ($loadedSampleId || $loadedSubjectObservationId)) { $existing = true; } else { $existing = false; } $hiddens .= get_user_profile_hidden_inputs($attributes, $args, $existing, $auth['read']); $customAttributeTabs = get_attribute_tabs($attributes); // remove added comment controls unless editing an existing sample if ($mode !== MODE_EXISTING || helper_base::$form_mode === 'ERRORS') { $controls = helper_base::explode_lines($args['structure']); $new_controls = array(); foreach ($controls as $control) { if ($control !== '[show added sample comments]' && $control !== '[add sample comment]') { $new_controls[] = $control; } } $args['structure'] = implode("\r\n", $new_controls); } $tabs = self::get_all_tabs($args['structure'], $customAttributeTabs); $r .= "<div id=\"controls\">\n"; // Build a list of the tabs that actually have content $tabHtml = self::get_tab_html($tabs, $auth, $args, $attributes, $hiddens); // Output the dynamic tab headers if ($args['interface'] != 'one_page') { $headerOptions = array('tabs' => array()); foreach ($tabHtml as $tab => $tabContent) { $alias = preg_replace('/[^a-zA-Z0-9]/', '', strtolower($tab)); $tabtitle = lang::get("LANG_Tab_{$alias}"); if ($tabtitle == "LANG_Tab_{$alias}") { // if no translation provided, we'll just use the standard heading $tabtitle = $tab; } $headerOptions['tabs']['#' . $alias] = $tabtitle; } $r .= data_entry_helper::tab_header($headerOptions); data_entry_helper::enable_tabs(array('divId' => 'controls', 'style' => $args['interface'], 'progressBar' => isset($args['tabProgress']) && $args['tabProgress'] == true)); } // Output the dynamic tab content $pageIdx = 0; foreach ($tabHtml as $tab => $tabContent) { // get a machine readable alias for the heading $tabalias = preg_replace('/[^a-zA-Z0-9]/', '', strtolower($tab)); $r .= '<div id="' . $tabalias . '">' . "\n"; // For wizard include the tab title as a header. if ($args['interface'] == 'wizard') { $r .= '<h1>' . $headerOptions['tabs']['#' . $tabalias] . '</h1>'; } $r .= $tabContent; // Add any buttons required at the bottom of the tab if ($args['interface'] == 'wizard') { $r .= data_entry_helper::wizard_buttons(array('divId' => 'controls', 'page' => $pageIdx === 0 ? 'first' : ($pageIdx == count($tabHtml) - 1 ? 'last' : 'middle'))); } elseif ($pageIdx == count($tabHtml) - 1 && !($args['interface'] == 'tabs' && $args['save_button_below_all_pages'])) { // last part of a non wizard interface must insert a save button, unless it is tabbed interface with save button beneath all pages $r .= "<input type=\"submit\" class=\"ui-state-default ui-corner-all\" id=\"save-button\" value=\"" . lang::get('LANG_Save') . "\" />\n"; } $pageIdx++; $r .= "</div>\n"; } $r .= "</div>\n"; if ($args['interface'] == 'tabs' && $args['save_button_below_all_pages']) { $r .= "<input type=\"submit\" class=\"ui-state-default ui-corner-all\" id=\"save-button\" value=\"" . lang::get('LANG_Save') . "\" />\n"; } if (!empty(data_entry_helper::$validation_errors)) { $r .= data_entry_helper::dump_remaining_errors(); } $r .= "</form>"; if (method_exists(get_called_class(), 'getTrailerHTML')) { $r .= call_user_func(array(get_called_class(), 'getTrailerHTML'), true, $args); } return $r; }
/** * Return the generated form output. * @return Form HTML. */ public static function get_form($args, $node) { define("MODE_GRID", 0); define("MODE_NEW_SAMPLE", 1); define("MODE_EXISTING", 2); self::parse_defaults($args); self::getArgDefaults($args); global $user; $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']); $svcUrl = data_entry_helper::$base_url . '/index.php/services'; self::$auth = $auth; $mode = isset($args['no_grid']) && $args['no_grid'] ? MODE_NEW_SAMPLE : MODE_GRID; // default mode when no grid set to false - display grid of existing data // mode MODE_EXISTING: display existing sample $loadedSampleId = null; $loadedOccurrenceId = null; 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('mnhnld1', $_POST)) { iform_loctools_deletelocations($node); foreach ($_POST as $key => $value) { $parts = explode(':', $key); iform_loctools_insertlocation($node, $parts[2], $parts[1]); } } } else { if (!is_null(data_entry_helper::$entity_to_load)) { $mode = MODE_EXISTING; // errors with new sample, entity populated with post, so display this data. } } // else valid save, so go back to gridview: default mode 0 } if (array_key_exists('sample_id', $_GET)) { $mode = MODE_EXISTING; $loadedSampleId = $_GET['sample_id']; } if (array_key_exists('occurrence_id', $_GET)) { $mode = MODE_EXISTING; $loadedOccurrenceId = $_GET['occurrence_id']; } if ($mode != MODE_EXISTING && array_key_exists('newSample', $_GET)) { $mode = MODE_NEW_SAMPLE; data_entry_helper::$entity_to_load = array(); } // else default to mode MODE_GRID or MODE_NEW_SAMPLE depending on no_grid parameter self::$mode = $mode; // default mode MODE_GRID : display grid of the samples to add a new one // or edit an existing one. if ($mode == MODE_GRID) { $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'])); $tabs = array('#sampleList' => lang::get('LANG_Main_Samples_Tab')); if ($args['includeLocTools'] && iform_loctools_checkaccess($node, 'admin')) { $tabs['#setLocations'] = lang::get('LANG_Allocate_Locations'); } if (count($tabs) > 1) { $r .= "<div id=\"controls\">" . data_entry_helper::enable_tabs(array('divId' => 'controls', 'active' => '#sampleList')) . "<div id=\"temp\"></div>"; $r .= data_entry_helper::tab_header(array('tabs' => $tabs)); } $r .= "<div id=\"sampleList\">" . self::getSampleListGrid($args, $node, $auth, $attributes) . "</div>"; if ($args['includeLocTools'] && iform_loctools_checkaccess($node, 'admin')) { $r .= ' <div id="setLocations"> <form method="post"> <input type="hidden" id="mnhnld1" name="mnhnld1" value="mnhnld1" /><table border="1"><tr><td></td>'; $url = $svcUrl . '/data/location?mode=json&view=detail&auth_token=' . $auth['read']['auth_token'] . "&nonce=" . $auth['read']["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); foreach ($userlist as $uid => $a_user) { $r .= '<td>' . $a_user->name . '</td>'; } $r .= "</tr>"; if (!empty($entities)) { foreach ($entities as $entity) { if (!$entity["parent_id"]) { // only assign parent locations. $r .= "<tr><td>" . $entity["name"] . "</td>"; $defaultuserids = iform_loctools_getusers($node, $entity["id"]); foreach ($userlist as $uid => $a_user) { $r .= '<td><input type="checkbox" name="location:' . $entity["id"] . ':' . $uid . (in_array($uid, $defaultuserids) ? '" checked="checked"' : '"') . '></td>'; } $r .= "</tr>"; } } } $r .= "</table>\n <input type=\"submit\" class=\"ui-state-default ui-corner-all\" value=\"" . lang::get('LANG_Save_Location_Allocations') . "\" />\n </form>\n </div>"; } if (count($tabs) > 1) { // close tabs div if present $r .= "</div>"; } return $r; } if ($mode == MODE_EXISTING) { data_entry_helper::$entity_to_load = array(); // Displaying an existing sample. If we know the occurrence ID, and don't know the sample ID or are displaying just one occurrence // rather than a grid of occurrences then we must load the occurrence data. if ($loadedOccurrenceId && (!$loadedSampleId || !self::getGridMode($args))) { // The URL has provided us with an occurrence ID, but we need to know the sample ID as well. $url = $svcUrl . "/data/occurrence/{$loadedOccurrenceId}"; $url .= "?mode=json&view=detail&auth_token=" . $auth['read']['auth_token'] . "&nonce=" . $auth['read']["nonce"]; $session = curl_init($url); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); $entity = json_decode(curl_exec($session), true); // Get the sample ID for the occurrence. This overwrites it if supply in GET but did not match the occurrence's sample $loadedSampleId = $entity[0]['sample_id']; if (!self::getGridMode($args)) { // populate the entity to load with the single occurrence's data foreach ($entity[0] as $key => $value) { data_entry_helper::$entity_to_load['occurrence:' . $key] = $value; } } } if ($loadedSampleId) { $url = $svcUrl . '/data/sample/' . $loadedSampleId; $url .= "?mode=json&view=detail&auth_token=" . $auth['read']['auth_token'] . "&nonce=" . $auth['read']["nonce"]; $session = curl_init($url); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); $entity = json_decode(curl_exec($session), true); // Build a list of the sample data. foreach ($entity[0] as $key => $value) { data_entry_helper::$entity_to_load['sample:' . $key] = $value; } 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. } } // atributes must be fetched after the entity to load is filled in - this is because the id gets filled in then! $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' => $auth['read'], 'survey_id' => $args['survey_id'])); // Make sure the form action points back to this page $reload = data_entry_helper::get_reload_link_parts(); $reloadPath = $reload['path']; $r = "<form method=\"post\" id=\"entry_form\" action=\"{$reloadPath}\">\n"; // Get authorisation tokens to update the Warehouse, plus any other hidden data. $hiddens = $auth['write'] . "<input type=\"hidden\" id=\"website_id\" name=\"website_id\" value=\"" . $args['website_id'] . "\" />\n" . "<input type=\"hidden\" id=\"survey_id\" name=\"survey_id\" value=\"" . $args['survey_id'] . "\" />\n"; if (isset(data_entry_helper::$entity_to_load['sample:id'])) { $hiddens .= "<input type=\"hidden\" id=\"sample:id\" name=\"sample:id\" value=\"" . data_entry_helper::$entity_to_load['sample:id'] . "\" />\n"; } if (isset(data_entry_helper::$entity_to_load['occurrence:id'])) { $hiddens .= "<input type=\"hidden\" id=\"occurrence:id\" name=\"occurrence:id\" value=\"" . data_entry_helper::$entity_to_load['occurrence:id'] . "\" />\n"; } // Check if Record Status is included as a control. If not, then add it as a hidden. $arr = explode("\r\n", $args['structure']); if (!in_array('[record status]', $arr)) { $value = isset($args['defaults']['occurrence:record_status']) ? $args['defaults']['occurrence:record_status'] : 'C'; $hiddens .= "<input type=\"hidden\" id=\"occurrence:record_status\" name=\"occurrence:record_status\" value=\"{$value}\" />\n"; } // request automatic JS validation if (!isset($args['clientSideValidation']) || $args['clientSideValidation']) { data_entry_helper::enable_validation('entry_form'); } // If logged in, output some hidden data about the user foreach ($attributes as &$attribute) { if (strcasecmp($attribute['caption'], 'cms user id') == 0) { if ($logged_in) { $attribute['value'] = $user->uid; } $attribute['handled'] = true; // user id attribute is never displayed } elseif (strcasecmp($attribute['caption'], 'cms username') == 0) { if ($logged_in) { $attribute['value'] = $user->name; } $attribute['handled'] = true; // username attribute is never displayed } elseif (strcasecmp($attribute['caption'], 'email') == 0) { if ($logged_in) { if ($args['emailShow'] != true) { // email attribute is not displayed $attribute['value'] = $user->mail; $attribute['handled'] = true; } else { $attribute['default'] = $user->mail; } } } elseif ((strcasecmp($attribute['caption'], 'first name') == 0 || strcasecmp($attribute['caption'], 'last name') == 0 || strcasecmp($attribute['caption'], 'surname') == 0) && $logged_in) { if ($args['nameShow'] != true) { // name attributes are not displayed $attribute['handled'] = true; } } if (isset($attribute['value'])) { $hiddens .= '<input type="hidden" name="' . $attribute['fieldname'] . '" value="' . $attribute['value'] . '" />' . "\n"; } } $customAttributeTabs = self::get_attribute_tabs($attributes); $tabs = self::get_all_tabs($args['structure'], $customAttributeTabs); $r .= "<div id=\"controls\">\n"; // Build a list of the tabs that actually have content $tabHtml = self::get_tab_html($tabs, $auth, $args, $attributes, $hiddens); // Output the dynamic tab headers if ($args['interface'] != 'one_page') { $headerOptions = array('tabs' => array()); foreach ($tabHtml as $tab => $tabContent) { $alias = preg_replace('/[^a-zA-Z0-9]/', '', strtolower($tab)); $tabtitle = lang::get("LANG_Tab_{$alias}"); if ($tabtitle == "LANG_Tab_{$alias}") { // if no translation provided, we'll just use the standard heading $tabtitle = $tab; } $headerOptions['tabs']['#' . $alias] = $tabtitle; } $r .= data_entry_helper::tab_header($headerOptions); data_entry_helper::enable_tabs(array('divId' => 'controls', 'style' => $args['interface'], 'progressBar' => isset($args['tabProgress']) && $args['tabProgress'] == true)); } // Output the dynamic tab content $pageIdx = 0; foreach ($tabHtml as $tab => $tabContent) { // get a machine readable alias for the heading $tabalias = preg_replace('/[^a-zA-Z0-9]/', '', strtolower($tab)); $r .= '<div id="' . $tabalias . '">' . "\n"; // For wizard include the tab title as a header. if ($args['interface'] == 'wizard') { $r .= '<h1>' . $headerOptions['tabs']['#' . $tabalias] . '</h1>'; } $r .= $tabContent; // Add any buttons required at the bottom of the tab if ($args['interface'] == 'wizard') { $r .= data_entry_helper::wizard_buttons(array('divId' => 'controls', 'page' => $pageIdx === 0 ? 'first' : ($pageIdx == count($tabs) - 1 ? 'last' : 'middle'))); } elseif ($pageIdx == count($tabs) - 1 && !($args['interface'] == 'tabs' && $args['save_button_below_all_pages'])) { // last part of a non wizard interface must insert a save button, unless it is tabbed interface with save button beneath all pages $r .= "<input type=\"submit\" class=\"ui-state-default ui-corner-all\" value=\"" . lang::get('LANG_Save') . "\" />\n"; } $pageIdx++; $r .= "</div>\n"; } $r .= "</div>\n"; if ($args['interface'] == 'tabs' && $args['save_button_below_all_pages']) { $r .= "<input type=\"submit\" class=\"ui-state-default ui-corner-all\" value=\"" . lang::get('LANG_Save') . "\" />\n"; } 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 // @todo Why is this not in the data entry helper, and is it really needed? if (self::$want_location_layer) { data_entry_helper::$onload_javascript .= "\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=" . $auth['read']['auth_token'] . "&nonce=" . $auth['read']["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 if(data[i].centroid_geom){\n feature = parser.read(data[i].centroid_geom);\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 feature = parser.read(data[i].boundary_geom);\n feature.style = {strokeColor: \"Blue\",\n strokeWidth: 2,\n label: (data[i].centroid_geom ? \"\" : data[i].name)};\n locationLayer.addFeatures([feature]);\n }\n }\n var extent=locationLayer.getDataExtent();\n if (extent!==null) {\n locationLayer.map.zoomToExtent(extent);\n }\n }\n\t\t }\n );\n }\n};\njQuery('#imp-location').unbind('change');\njQuery('#imp-location').change(function(){\n\tlocationChange(this);\n});\n\nvar updatePlaceTabHandler = function(event, ui) { \n if (ui.panel.id=='place') {\n // upload location & sref initial values into map.\n jQuery('#imp-location').change();\n jQuery('#imp-sref').change();\n jQuery('#controls').unbind('tabsshow', updatePlaceTabHandler);\n }\n}\njQuery('#controls').bind('tabsshow', updatePlaceTabHandler);\n\n"; } $r .= self::link_species_popups($args); return $r; }
/** * Return the generated form output. * @return Form HTML. */ public static function get_form($args, $node) { self::parse_defaults($args); self::getArgDefaults($args); global $user; $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']); $svcUrl = data_entry_helper::$base_url . '/index.php/services'; $mode = 0; // default mode : display grid of existing data // mode 1: display new sample // mode 2: display existing sample $loadID = null; if ($_POST) { if (!is_null(data_entry_helper::$entity_to_load)) { $mode = 2; // errors with new sample, entity populated with post, so display this data. } // else valid save, so go back to gridview: default mode 0 } elseif (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 $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' => $auth['read'], 'survey_id' => $args['survey_id'])); /////////////////////////////////////////////////////////////////// // default mode 0 : display grid of the samples to add a new one // or edit an existing one. /////////////////////////////////////////////////////////////////// if ($mode == 0) { return self::getSampleListGrid($args, $node, $auth, $attributes); } /////////////////////////////////////////////////////////////////// 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) { $url = $svcUrl . '/data/sample/' . $loadID; $url .= "?mode=json&view=detail&auth_token=" . $auth['read']['auth_token'] . "&nonce=" . $auth['read']["nonce"]; $session = curl_init($url); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); $entity = json_decode(curl_exec($session), true); // Build a list of the sample data. data_entry_helper::$entity_to_load = array(); foreach ($entity[0] as $key => $value) { data_entry_helper::$entity_to_load['sample:' . $key] = $value; } 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' => $auth['read']); // $r .= "<h1>MODE = ".$mode."</h1>"; // $r .= "<h2>readOnly = ".$readOnly."</h2>"; $r = "<form method=\"post\" id=\"entry_form\">\n"; // Get authorisation tokens to update the Warehouse, plus any other hidden data. $hiddens = $auth['write'] . "<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"; if (array_key_exists('sample:id', data_entry_helper::$entity_to_load)) { $hiddens .= "<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)) { $hiddens .= "<input type=\"hidden\" id=\"occurrence:id\" name=\"occurrence:id\" value=\"" . data_entry_helper::$entity_to_load['occurrence:id'] . "\" />\n"; } // Check if Record Status is included as a control. If not, then add it as a hidden. $arr = explode("\r\n", $args['structure']); if (!in_array('[record status]', $arr)) { $value = isset($args['defaults']['occurrence:record_status']) ? $args['defaults']['occurrence:record_status'] : 'C'; $hiddens .= "<input type=\"hidden\" id=\"occurrence:record_status\" name=\"occurrence:record_status\" value=\"{$value}\" />\n"; } // request automatic JS validation 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' => $auth['read'], 'survey_id' => $args['survey_id'])); // If logged in, output some hidden data about the user foreach ($attributes as &$attribute) { if (strcasecmp($attribute['caption'], 'cms user id') == 0) { if ($logged_in) { $attribute['value'] = $user->uid; } $attribute['handled'] = true; // user id attribute is never displayed } elseif (strcasecmp($attribute['caption'], 'cms username') == 0) { if ($logged_in) { $attribute['value'] = $user->name; } $attribute['handled'] = true; // username attribute is never displayed } elseif (strcasecmp($attribute['caption'], 'email') == 0) { if ($logged_in) { $attribute['value'] = $user->mail; $attribute['handled'] = true; // email attribute is displayed unless logged in } } elseif ((strcasecmp($attribute['caption'], 'first name') == 0 || strcasecmp($attribute['caption'], 'last name') == 0 || strcasecmp($attribute['caption'], 'surname') == 0) && $logged_in) { $attribute['handled'] = true; } // name attributes are displayed unless logged in if (isset($attribute['value'])) { $hiddens .= '<input type="hidden" name="' . $attribute['fieldname'] . '" value="' . $attribute['value'] . '" />' . "\n"; } } $customAttributeTabs = self::get_attribute_tabs($attributes); $tabs = self::get_all_tabs($args['structure'], $customAttributeTabs); $r .= "<div id=\"controls\">\n"; // Output the dynamic tab headers if ($args['interface'] != 'one_page') { $r .= "<ul>\n"; foreach ($tabs as $tab => $tabContent) { $alias = preg_replace('/[^a-zA-Z0-9]/', '', strtolower($tab)); $tabtitle = lang::get("LANG_Tab_{$alias}"); if ($tabtitle == "LANG_Tab_{$alias}") { // if no translation provided, we'll just use the standard heading $tabtitle = $tab; } $r .= ' <li><a href="#' . $alias . '"><span>' . $tabtitle . "</span></a></li>\n"; } $r .= "</ul>\n"; data_entry_helper::enable_tabs(array('divId' => 'controls', 'style' => $args['interface'])); } // Output the dynamic tab content $pageIdx = 0; foreach ($tabs as $tab => $tabContent) { // get a machine readable alias for the heading $tabalias = preg_replace('/[^a-zA-Z0-9]/', '', strtolower($tab)); $r .= '<div id="' . $tabalias . '">' . "\n"; if ($pageIdx == 0) { // output the hidden inputs on the first tab $r .= $hiddens; } // Now output the content of the tab. Use a for loop, not each, so we can treat several rows as one object for ($i = 0; $i < count($tabContent); $i++) { $component = $tabContent[$i]; if (preg_match('/\\A\\?[^¬]*\\?\\z/', trim($component)) === 1) { // Component surrounded by ? so represents a help text $helpText = substr(trim($component), 1, -1); $r .= '<p class="page-notice ui-state-highlight ui-corner-all">' . lang::get($helpText) . "</p>"; } elseif (preg_match('/\\A\\[[^¬]*\\]\\z/', trim($component)) === 1) { // Component surrounded by [] so represents a control $method = 'get_control_' . preg_replace('/[^a-zA-Z0-9]/', '', strtolower($component)); // Anything following the component that starts with @ is an option to pass to the control $options = array(); while ($i < count($tabContent) - 1 && substr($tabContent[$i + 1], 0, 1) == '@') { $i++; $option = explode('=', substr($tabContent[$i], 1)); $options[$option[0]] = $option[1]; } if (method_exists('iform_mnhnl_dynamic_1', $method)) { $r .= self::$method($auth, $args, $tabalias, $options); } elseif (trim($component) === '[*]') { $r .= self::get_attribute_html($attributes, $defAttrOptions, $tab); } else { $r .= "The form structure includes a control called {$component} which is not recognised.<br/>"; } } } // Add any buttons required at the bottom of the tab if ($args['interface'] == 'wizard') { $r .= data_entry_helper::wizard_buttons(array('divId' => 'controls', 'page' => $pageIdx === 0 ? 'first' : ($pageIdx == count($tabs) - 1 ? 'last' : 'middle'))); } elseif ($pageIdx == count($tabs) - 1 && !($args['interface'] == 'tabs' && $args['save_button_below_all_pages'])) { // last part of a non wizard interface must insert a save button, unless it is tabbed interface with save button beneath all pages $r .= "<input type=\"submit\" class=\"ui-state-default ui-corner-all\" value=\"" . lang::get('LANG_Save') . "\" />\n"; } $pageIdx++; $r .= "</div>\n"; } $r .= "</div>\n"; if ($args['interface'] == 'tabs' && $args['save_button_below_all_pages']) { $r .= "<input type=\"submit\" class=\"ui-state-default ui-corner-all\" value=\"" . lang::get('LANG_Save') . "\" />\n"; } 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=" . $auth['read']['auth_token'] . "&nonce=" . $auth['read']["nonce"] . "\" +\n\t\t\t\"&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 if(data[i].centroid_geom){\n feature = parser.read(data[i].centroid_geom);\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 feature = parser.read(data[i].boundary_geom);\n feature.style = {strokeColor: \"Blue\",\n strokeWidth: 2,\n label: (data[i].centroid_geom ? \"\" : data[i].name)};\n locationLayer.addFeatures([feature]);\n }\n }\n var extent=locationLayer.getDataExtent();\n if (extent!==null) {\n locationLayer.map.zoomToExtent(extent);\n }\n }\n\t\t }\n );\n }\n};\njQuery('#imp-location').unbind('change');\njQuery('#imp-location').change(function(){\n\tlocationChange(this);\n});\n\nvar updatePlaceTabHandler = function(event, ui) { \n if (ui.panel.id=='place') {\n // upload location & sref initial values into map.\n jQuery('#imp-location').change();\n jQuery('#imp-sref').change();\n jQuery('#controls').unbind('tabsshow', updatePlaceTabHandler);\n }\n}\njQuery('#controls').bind('tabsshow', updatePlaceTabHandler);\n\n"; 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; }
protected static function get_form_html($args, $auth, $attributes) { $r = call_user_func(array(self::$called_class, 'getHeader'), $args); $params = array($args, $auth, &$attributes); if (self::$mode === self::MODE_CLONE) { call_user_func_array(array(self::$called_class, 'cloneEntity'), $params); } $firstTabExtras = method_exists(self::$called_class, 'getFirstTabAdditionalContent') ? call_user_func_array(array(self::$called_class, 'getFirstTabAdditionalContent'), $params) : ''; $customAttributeTabs = get_attribute_tabs($attributes); $tabs = self::get_all_tabs($args['structure'], $customAttributeTabs); if (isset($tabs['-'])) { $hasControls = false; $r .= self::get_tab_content($auth, $args, '$tab' - '', $tabs['-'], 'above-tabs', $attributes, $hasControls); unset($tabs['-']); } $r .= "<div id=\"controls\">\n"; // Build a list of the tabs that actually have content $tabHtml = self::get_tab_html($tabs, $auth, $args, $attributes, $firstTabExtras); // Output the dynamic tab headers if ($args['interface'] != 'one_page') { $headerOptions = array('tabs' => array()); foreach ($tabHtml as $tab => $tabContent) { $alias = preg_replace('/[^a-zA-Z0-9]/', '', strtolower($tab)); $tabtitle = lang::get("LANG_Tab_{$alias}"); if ($tabtitle == "LANG_Tab_{$alias}") { // if no translation provided, we'll just use the standard heading $tabtitle = $tab; } $headerOptions['tabs']['#tab-' . $alias] = $tabtitle; } $r .= data_entry_helper::tab_header($headerOptions); data_entry_helper::enable_tabs(array('divId' => 'controls', 'style' => $args['interface'], 'progressBar' => isset($args['tabProgress']) && $args['tabProgress'] == true, 'navButtons' => isset($args['force_next_previous']) && $args['force_next_previous'])); } else { // ensure client side validation is activated if requested on single page forms. This is done in the enable_tabs bit above. // This is useful if we have custom client side validation. if (isset(data_entry_helper::$validated_form_id)) { data_entry_helper::$javascript .= "\n\$('#" . data_entry_helper::$validated_form_id . "').submit(function() {\n var tabinputs = \$('#" . data_entry_helper::$validated_form_id . "').find('input,select,textarea').not(':disabled,[name=],.scTaxonCell,.inactive');\n var tabtaxoninputs = \$('#" . data_entry_helper::$validated_form_id . " .scTaxonCell').find('input,select').not(':disabled');\n if ((tabinputs.length>0 && !tabinputs.valid()) || (tabtaxoninputs.length>0 && !tabtaxoninputs.valid())) {\n alert('" . lang::get('Before you can save the data on this form, some of the values in the input boxes need checking. ' . 'These have been highlighted on the form for you.') . "');\n return false;\n }\n return true;\n});\n"; } } // Output the dynamic tab content $pageIdx = 0; $singleSpeciesLabel = self::$singleSpeciesName; foreach ($tabHtml as $tab => $tabContent) { // get a machine readable alias for the heading $tabalias = 'tab-' . preg_replace('/[^a-zA-Z0-9]/', '', strtolower($tab)); $r .= "<div id=\"{$tabalias}\">\n"; //We only want to show the single species message to the user if they have selected the option and we are in single species mode. //We also want to only show it on the species tab otherwise in 'All one page' mode it will appear multiple times. if (isset($args['single_species_message']) && $args['single_species_message'] && $tabalias == 'tab-species' && isset($singleSpeciesLabel)) { $r .= '<div class="page-notice ui-state-highlight ui-corner-all">' . lang::get('You are submitting a record of {1}', $singleSpeciesLabel) . '</div>'; } // For wizard include the tab title as a header. if ($args['interface'] == 'wizard') { $r .= '<h1>' . $headerOptions['tabs']['#' . $tabalias] . '</h1>'; } $r .= $tabContent; if (isset($args['verification_panel']) && $args['verification_panel'] && $pageIdx == count($tabHtml) - 1) { $r .= data_entry_helper::verification_panel(array('readAuth' => $auth['read'], 'panelOnly' => true)); } // Add any buttons required at the bottom of the tab if ($args['interface'] === 'wizard' || $args['interface'] === 'tabs' && isset($args['force_next_previous']) && $args['force_next_previous']) { $r .= data_entry_helper::wizard_buttons(array('divId' => 'controls', 'page' => $pageIdx === 0 ? 'first' : ($pageIdx == count($tabHtml) - 1 ? 'last' : 'middle'), 'includeVerifyButton' => isset($args['verification_panel']) && $args['verification_panel'] && $pageIdx == count($tabHtml) - 1, 'includeSubmitButton' => self::$mode !== self::MODE_EXISTING_RO, 'includeDeleteButton' => self::$mode === self::MODE_EXISTING)); } elseif ($pageIdx == count($tabHtml) - 1) { // We need the verify button as well if this option is enabled if (isset($args['verification_panel']) && $args['verification_panel']) { $r .= '<button type="button" class="indicia-button" id="verify-btn">' . lang::get('Precheck my records') . "</button>\n"; } if (call_user_func(array(self::$called_class, 'include_save_buttons')) && !($args['interface'] == 'tabs' && isset($args['save_button_below_all_pages']) && $args['save_button_below_all_pages']) && method_exists(self::$called_class, 'getSubmitButtons')) { // last part of a non wizard interface must insert a save button, unless it is tabbed // interface with save button beneath all pages $r .= call_user_func(array(self::$called_class, 'getSubmitButtons'), $args); } } $pageIdx++; $r .= "</div>\n"; } $r .= "</div>\n"; if (method_exists(self::$called_class, 'getFooter')) { $r .= call_user_func(array(self::$called_class, 'getFooter'), $args); } if (method_exists(self::$called_class, 'link_species_popups')) { $r .= call_user_func(array(self::$called_class, 'link_species_popups'), $args); } return $r; }
/** * Return the generated form output. * @return Form HTML. */ public static function get_form($args, $node) { define("MODE_GRID", 0); define("MODE_NEW_SAMPLE", 1); define("MODE_EXISTING", 2); self::parse_defaults($args); self::getArgDefaults($args); global $user; $logged_in = $user->uid > 0; self::$node = $node; // Get authorisation tokens to update and read from the Warehouse. $auth = data_entry_helper::get_read_write_auth($args['website_id'], $args['password']); $svcUrl = data_entry_helper::$base_url . '/index.php/services'; self::$auth = $auth; $mode = isset($args['no_grid']) && $args['no_grid'] ? MODE_NEW_SAMPLE : MODE_GRID; // default mode when no grid set to false - display grid of existing data // mode MODE_EXISTING: display existing sample $loadedSampleId = null; $loadedOccurrenceId = null; 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 (function_exists('iform_loctools_checkaccess') && iform_loctools_checkaccess($node, 'admin') && array_key_exists('mnhnld1', $_POST)) { iform_loctools_deletelocations($node); foreach ($_POST as $key => $value) { $parts = explode(':', $key); iform_loctools_insertlocation($node, $parts[2], $parts[1]); } } } else { if (!is_null(data_entry_helper::$entity_to_load)) { $mode = MODE_EXISTING; // errors with new sample, entity populated with post, so display this data. } } // else valid save, so go back to gridview: default mode 0 } if (array_key_exists('sample_id', $_GET) && $_GET['sample_id'] != '{sample_id}') { $mode = MODE_EXISTING; $loadedSampleId = $_GET['sample_id']; } if (array_key_exists('occurrence_id', $_GET) && $_GET['occurrence_id'] != '{occurrence_id}') { $mode = MODE_EXISTING; $loadedOccurrenceId = $_GET['occurrence_id']; self::$occurrenceIds = array($loadedOccurrenceId); } if ($mode != MODE_EXISTING && array_key_exists('newSample', $_GET)) { $mode = MODE_NEW_SAMPLE; data_entry_helper::$entity_to_load = array(); } // else default to mode MODE_GRID or MODE_NEW_SAMPLE depending on no_grid parameter self::$mode = $mode; // default mode MODE_GRID : display grid of the samples to add a new one // or edit an existing one. if ($mode == MODE_GRID) { $r = ''; $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']), false); $tabs = array('#sampleList' => lang::get('LANG_Main_Samples_Tab')); if ($args['includeLocTools'] && function_exists('iform_loctools_checkaccess') && iform_loctools_checkaccess($node, 'admin')) { $tabs['#setLocations'] = lang::get('LANG_Allocate_Locations'); } if (method_exists(get_called_class(), 'getExtraGridModeTabs')) { $extraTabs = call_user_func(array(get_called_class(), 'getExtraGridModeTabs'), false, $auth['read'], $args, $attributes); if (is_array($extraTabs)) { $tabs = $tabs + $extraTabs; } } if (count($tabs) > 1) { $r .= "<div id=\"controls\">" . data_entry_helper::enable_tabs(array('divId' => 'controls', 'active' => '#sampleList')) . "<div id=\"temp\"></div>"; $r .= data_entry_helper::tab_header(array('tabs' => $tabs)); } $r .= "<div id=\"sampleList\">" . call_user_func(array(get_called_class(), 'getSampleListGrid'), $args, $node, $auth, $attributes) . "</div>"; if ($args['includeLocTools'] && function_exists('iform_loctools_checkaccess') && iform_loctools_checkaccess($node, 'admin')) { $r .= ' <div id="setLocations"> <form method="post"> <input type="hidden" id="mnhnld1" name="mnhnld1" value="mnhnld1" /><table border="1"><tr><td></td>'; $url = $svcUrl . '/data/location?mode=json&view=detail&auth_token=' . $auth['read']['auth_token'] . "&nonce=" . $auth['read']["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); foreach ($userlist as $uid => $a_user) { $r .= '<td>' . $a_user->name . '</td>'; } $r .= "</tr>"; if (!empty($entities)) { foreach ($entities as $entity) { if (!$entity["parent_id"]) { // only assign parent locations. $r .= "<tr><td>" . $entity["name"] . "</td>"; $defaultuserids = iform_loctools_getusers($node, $entity["id"]); foreach ($userlist as $uid => $a_user) { $r .= '<td><input type="checkbox" name="location:' . $entity["id"] . ':' . $uid . (in_array($uid, $defaultuserids) ? '" checked="checked"' : '"') . '></td>'; } $r .= "</tr>"; } } } $r .= "</table>\n <input type=\"submit\" class=\"ui-state-default ui-corner-all\" value=\"" . lang::get('LANG_Save_Location_Allocations') . "\" />\n </form>\n </div>"; } if (method_exists(get_called_class(), 'getExtraGridModeTabs')) { $r .= call_user_func(array(get_called_class(), 'getExtraGridModeTabs'), true, $auth['read'], $args, $attributes); } if (count($tabs) > 1) { // close tabs div if present $r .= "</div>"; } return $r; } if ($mode == MODE_EXISTING && is_null(data_entry_helper::$entity_to_load)) { // only load if not in error situation data_entry_helper::$entity_to_load = array(); // Displaying an existing sample. If we know the occurrence ID, and don't know the sample ID or are displaying just one occurrence // rather than a grid of occurrences then we must load the occurrence data to get the sample id. if ($loadedOccurrenceId && (!$loadedSampleId || !self::getGridMode($args))) { data_entry_helper::load_existing_record($auth['read'], 'occurrence', $loadedOccurrenceId); // Get the sample ID for the occurrence. This overwrites it if supply in GET but did not match the occurrence's sample $loadedSampleId = data_entry_helper::$entity_to_load['occurrence:sample_id']; if (self::getGridMode($args)) { // in grid mode, we only needed to load the occurrence to find out the sample id. data_entry_helper::$entity_to_load = array(); } } if ($loadedSampleId) { data_entry_helper::load_existing_record($auth['read'], 'sample', $loadedSampleId); } } // attributes must be fetched after the entity to load is filled in - this is because the id gets filled in then! $attrOpts = array('id' => data_entry_helper::$entity_to_load['sample:id'], 'valuetable' => 'sample_attribute_value', 'attrtable' => 'sample_attribute', 'key' => 'sample_id', 'fieldprefix' => 'smpAttr', 'extraParams' => $auth['read'], 'survey_id' => $args['survey_id']); // select only the custom attributes that are for this sample method or all sample methods, if this // form is for a specific sample method. if (!empty($args['sample_method_id'])) { $attrOpts['sample_method_id'] = $args['sample_method_id']; } $attributes = data_entry_helper::getAttributes($attrOpts, false); //// Make sure the form action points back to this page $reload = data_entry_helper::get_reload_link_parts(); unset($reload['params']['sample_id']); unset($reload['params']['occurrence_id']); unset($reload['params']['newSample']); $reloadPath = $reload['path']; if (count($reload['params'])) { $reloadPath .= '?' . http_build_query($reload['params']); } $r = "<form method=\"post\" id=\"entry_form\" action=\"{$reloadPath}\">\n"; // Get authorisation tokens to update the Warehouse, plus any other hidden data. $hiddens = $auth['write'] . "<input type=\"hidden\" id=\"website_id\" name=\"website_id\" value=\"" . $args['website_id'] . "\" />\n" . "<input type=\"hidden\" id=\"survey_id\" name=\"survey_id\" value=\"" . $args['survey_id'] . "\" />\n"; if (!empty($args['sample_method_id'])) { $hiddens .= '<input type="hidden" name="sample:sample_method_id" value="' . $args['sample_method_id'] . '"/>'; } if (isset(data_entry_helper::$entity_to_load['sample:id'])) { $hiddens .= "<input type=\"hidden\" id=\"sample:id\" name=\"sample:id\" value=\"" . data_entry_helper::$entity_to_load['sample:id'] . "\" />\n"; } if (isset(data_entry_helper::$entity_to_load['occurrence:id'])) { $hiddens .= "<input type=\"hidden\" id=\"occurrence:id\" name=\"occurrence:id\" value=\"" . data_entry_helper::$entity_to_load['occurrence:id'] . "\" />\n"; } // Check if Record Status is included as a control. If not, then add it as a hidden. $arr = explode("\r\n", $args['structure']); if (!in_array('[record status]', $arr)) { $value = isset($args['defaults']['occurrence:record_status']) ? $args['defaults']['occurrence:record_status'] : 'C'; $hiddens .= "<input type=\"hidden\" id=\"occurrence:record_status\" name=\"occurrence:record_status\" value=\"{$value}\" />\n"; } // request automatic JS validation if (!isset($args['clientSideValidation']) || $args['clientSideValidation']) { data_entry_helper::enable_validation('entry_form'); } // If logged in, output some hidden data about the user if (isset($args['copyFromProfile']) && $args['copyFromProfile'] == true) { self::profile_load_all_profile($user); } foreach ($attributes as &$attribute) { $attrPropName = 'profile_' . strtolower(str_replace(' ', '_', $attribute['caption'])); if (isset($args['copyFromProfile']) && $args['copyFromProfile'] == true && isset($user->{$attrPropName})) { if ($args['nameShow'] == true) { $attribute['default'] = $user->{$attrPropName}; } else { // profile attributes are not displayed as the user is logged in $attribute['handled'] = true; $attribute['value'] = $user->{$attrPropName}; } } elseif (strcasecmp($attribute['caption'], 'cms user id') == 0) { if ($logged_in) { $attribute['value'] = $user->uid; } $attribute['handled'] = true; // user id attribute is never displayed } elseif (strcasecmp($attribute['caption'], 'cms username') == 0) { if ($logged_in) { $attribute['value'] = $user->name; } $attribute['handled'] = true; // username attribute is never displayed } elseif (strcasecmp($attribute['caption'], 'email') == 0) { if ($logged_in) { if ($args['emailShow'] != true) { // email attribute is not displayed $attribute['value'] = $user->mail; $attribute['handled'] = true; } else { $attribute['default'] = $user->mail; } } } elseif ((strcasecmp($attribute['caption'], 'first name') == 0 || strcasecmp($attribute['caption'], 'last name') == 0 || strcasecmp($attribute['caption'], 'surname') == 0) && $logged_in) { if ($args['nameShow'] != true) { // name attributes are not displayed because we have the users login $attribute['handled'] = true; } } // If we have a value for one of the user login attributes then we need to output this value. BUT, for existing data // we must not overwrite the user who created the record. if (isset($attribute['value']) && $mode != MODE_EXISTING) { $hiddens .= '<input type="hidden" name="' . $attribute['fieldname'] . '" value="' . $attribute['value'] . '" />' . "\n"; } } $customAttributeTabs = get_attribute_tabs($attributes); $tabs = self::get_all_tabs($args['structure'], $customAttributeTabs); $r .= "<div id=\"controls\">\n"; // Build a list of the tabs that actually have content $tabHtml = self::get_tab_html($tabs, $auth, $args, $attributes, $hiddens); // Output the dynamic tab headers if ($args['interface'] != 'one_page') { $headerOptions = array('tabs' => array()); foreach ($tabHtml as $tab => $tabContent) { $alias = preg_replace('/[^a-zA-Z0-9]/', '', strtolower($tab)); $tabtitle = lang::get("LANG_Tab_{$alias}"); if ($tabtitle == "LANG_Tab_{$alias}") { // if no translation provided, we'll just use the standard heading $tabtitle = $tab; } $headerOptions['tabs']['#' . $alias] = $tabtitle; } $r .= data_entry_helper::tab_header($headerOptions); data_entry_helper::enable_tabs(array('divId' => 'controls', 'style' => $args['interface'], 'progressBar' => isset($args['tabProgress']) && $args['tabProgress'] == true)); } // Output the dynamic tab content $pageIdx = 0; foreach ($tabHtml as $tab => $tabContent) { // get a machine readable alias for the heading $tabalias = preg_replace('/[^a-zA-Z0-9]/', '', strtolower($tab)); $r .= '<div id="' . $tabalias . '">' . "\n"; // For wizard include the tab title as a header. if ($args['interface'] == 'wizard') { $r .= '<h1>' . $headerOptions['tabs']['#' . $tabalias] . '</h1>'; } $r .= $tabContent; // Add any buttons required at the bottom of the tab if ($args['interface'] == 'wizard') { $r .= data_entry_helper::wizard_buttons(array('divId' => 'controls', 'page' => $pageIdx === 0 ? 'first' : ($pageIdx == count($tabHtml) - 1 ? 'last' : 'middle'))); } elseif ($pageIdx == count($tabHtml) - 1 && !($args['interface'] == 'tabs' && $args['save_button_below_all_pages'])) { // last part of a non wizard interface must insert a save button, unless it is tabbed interface with save button beneath all pages $r .= "<input type=\"submit\" class=\"ui-state-default ui-corner-all\" id=\"save-button\" value=\"" . lang::get('LANG_Save') . "\" />\n"; } $pageIdx++; $r .= "</div>\n"; } $r .= "</div>\n"; if ($args['interface'] == 'tabs' && $args['save_button_below_all_pages']) { $r .= "<input type=\"submit\" class=\"ui-state-default ui-corner-all\" id=\"save-button\" value=\"" . lang::get('LANG_Save') . "\" />\n"; } if (!empty(data_entry_helper::$validation_errors)) { $r .= data_entry_helper::dump_remaining_errors(); } $r .= "</form>"; $r .= self::link_species_popups($args); return $r; }
protected static function get_form_html($args, $auth, $attributes) { $r = call_user_func(array(self::$called_class, 'getHeader'), $args); $params = array($args, $auth, &$attributes); if (self::$mode === self::MODE_CLONE) { call_user_func_array(array(self::$called_class, 'cloneEntity'), $params); } $firstTabExtras = method_exists(self::$called_class, 'getFirstTabAdditionalContent') ? call_user_func_array(array(self::$called_class, 'getFirstTabAdditionalContent'), $params) : ''; $customAttributeTabs = get_attribute_tabs($attributes); $tabs = self::get_all_tabs($args['structure'], $customAttributeTabs); if (isset($tabs['-'])) { $hasControls = false; $r .= self::get_tab_content($auth, $args, '$tab' - '', $tabs['-'], 'above-tabs', $attributes, $hasControls); unset($tabs['-']); } $r .= "<div id=\"controls\">\n"; // Build a list of the tabs that actually have content $tabHtml = self::get_tab_html($tabs, $auth, $args, $attributes, $firstTabExtras); // Output the dynamic tab headers if ($args['interface'] != 'one_page') { $headerOptions = array('tabs' => array()); foreach ($tabHtml as $tab => $tabContent) { $alias = preg_replace('/[^a-zA-Z0-9]/', '', strtolower($tab)); $tabtitle = lang::get("LANG_Tab_{$alias}"); if ($tabtitle == "LANG_Tab_{$alias}") { // if no translation provided, we'll just use the standard heading $tabtitle = $tab; } $headerOptions['tabs']['#tab-' . $alias] = $tabtitle; } $r .= data_entry_helper::tab_header($headerOptions); data_entry_helper::enable_tabs(array('divId' => 'controls', 'style' => $args['interface'], 'progressBar' => isset($args['tabProgress']) && $args['tabProgress'] == true)); } // Output the dynamic tab content $pageIdx = 0; $singleSpeciesLabel = self::$singleSpeciesName; foreach ($tabHtml as $tab => $tabContent) { // get a machine readable alias for the heading $tabalias = 'tab-' . preg_replace('/[^a-zA-Z0-9]/', '', strtolower($tab)); $r .= "<div id=\"{$tabalias}\">\n"; //We only want to show the single species message to the user if they have selected the option and we are in single species mode. //We also want to only show it on the species tab otherwise in 'All one page' mode it will appear multple times. if (isset($args['single_species_message']) && $args['single_species_message'] && $tabalias == 'tab-species' && isset($singleSpeciesLabel)) { $r .= '<div class="page-notice ui-state-highlight ui-corner-all">You are submitting a record of ' . "{$singleSpeciesLabel}</div>"; } // For wizard include the tab title as a header. if ($args['interface'] == 'wizard') { $r .= '<h1>' . $headerOptions['tabs']['#' . $tabalias] . '</h1>'; } $r .= $tabContent; if (isset($args['verification_panel']) && $args['verification_panel'] && $pageIdx == count($tabHtml) - 1) { $r .= data_entry_helper::verification_panel(array('readAuth' => $auth['read'], 'panelOnly' => true)); } // Add any buttons required at the bottom of the tab if ($args['interface'] == 'wizard') { $r .= data_entry_helper::wizard_buttons(array('divId' => 'controls', 'page' => $pageIdx === 0 ? 'first' : ($pageIdx == count($tabHtml) - 1 ? 'last' : 'middle'), 'includeVerifyButton' => isset($args['verification_panel']) && $args['verification_panel'] && $pageIdx == count($tabHtml) - 1, 'includeSubmitButton' => self::$mode !== self::MODE_EXISTING_RO, 'includeDeleteButton' => self::$mode === self::MODE_EXISTING)); } elseif ($pageIdx == count($tabHtml) - 1) { // We need the verify button as well if this option is enabled if (isset($args['verification_panel']) && $args['verification_panel']) { $r .= '<button type="button" class="indicia-button" id="verify-btn">' . lang::get('Precheck my records') . "</button>\n"; } if (call_user_func(array(self::$called_class, 'include_save_buttons')) && !($args['interface'] == 'tabs' && isset($args['save_button_below_all_pages']) && $args['save_button_below_all_pages']) && method_exists(self::$called_class, 'getSubmitButtons')) { // last part of a non wizard interface must insert a save button, unless it is tabbed // interface with save button beneath all pages $r .= call_user_func(array(self::$called_class, 'getSubmitButtons'), $args); } } $pageIdx++; $r .= "</div>\n"; } $r .= "</div>\n"; if (method_exists(self::$called_class, 'getFooter')) { $r .= call_user_func(array(self::$called_class, 'getFooter'), $args); } if (method_exists(self::$called_class, 'link_species_popups')) { $r .= call_user_func(array(self::$called_class, 'link_species_popups'), $args); } 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 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; }
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; }
protected static function get_form_sampleoccurrence($args, $node) { // attributes must be fetched after the entity to load is filled in - this is because the id gets filled in then! $cancelUrl = self::$currentUrl; $cancelUrl .= strpos($cancelUrl, '?') === false ? '?' : '&'; $cancelUrl .= "supersample_id=" . data_entry_helper::$entity_to_load['sample:parent_id']; $attributes = data_entry_helper::getAttributes(array('id' => data_entry_helper::$entity_to_load['sample:id'], 'valuetable' => 'sample_attribute_value', 'attrtable' => 'sample_attribute', 'key' => 'sample_id', 'fieldprefix' => 'smpAttr', 'extraParams' => self::$auth['read'], 'survey_id' => $args['survey_id'])); if (self::$mode == MODE_EXISTING_OCCURRENCE && self::$gridmode == false && isset(data_entry_helper::$entity_to_load['sample:id'])) { $cloneEntity = data_entry_helper::$entity_to_load; $occList = data_entry_helper::preload_species_checklist_occurrences(data_entry_helper::$entity_to_load['sample:id'], self::$auth['read'], $args['occurrence_images']); foreach ($occList as $id => $taxon) { self::$occurrenceIds[] = $id; } if (count(self::$occurrenceIds) > 1) { self::$gridmode = true; data_entry_helper::$entity_to_load = $cloneEntity; } } // Make sure the form action points back to this page $r = "<form method=\"post\" id=\"entry_form\" action=\"" . self::$currentUrl . "\">\n"; // Get authorisation tokens to update the Warehouse, plus any other hidden data. $hiddens = self::$auth['write'] . "<input type=\"hidden\" id=\"website_id\" name=\"website_id\" value=\"" . $args['website_id'] . "\" />\n" . "<input type=\"hidden\" id=\"survey_id\" name=\"survey_id\" value=\"" . $args['survey_id'] . "\" />\n" . "<input type=\"hidden\" id=\"parent_id\" name=\"sample:parent_id\" value=\"" . data_entry_helper::$entity_to_load['sample:parent_id'] . "\" />\n" . "<input type=\"hidden\" id=\"date\" name=\"sample:date\" value=\"" . data_entry_helper::$entity_to_load['sample:date'] . "\" />\n"; if (isset(data_entry_helper::$entity_to_load['sample:id'])) { $hiddens .= "<input type=\"hidden\" id=\"sample:id\" name=\"sample:id\" value=\"" . data_entry_helper::$entity_to_load['sample:id'] . "\" />\n"; } // Check if Record Status is included as a control. If not, then add it as a hidden. $arr = explode("\r\n", $args['structure']); if (!in_array('[record status]', $arr)) { $value = isset($args['defaults']['occurrence:record_status']) ? $args['defaults']['occurrence:record_status'] : 'C'; $hiddens .= "<input type=\"hidden\" id=\"occurrence:record_status\" name=\"occurrence:record_status\" value=\"{$value}\" />\n"; } // request automatic JS validation if (!isset($args['clientSideValidation']) || $args['clientSideValidation']) { data_entry_helper::enable_validation('entry_form'); } self::set_attribute_default_block($attributes); $tabs = self::get_all_tabs($args['occurrence_structure'], array()); $r .= "<div id=\"controls\">\n"; // Build a list of the tabs that actually have content $tabHtml = self::get_tab_html($tabs, self::$auth, $args, $attributes, $hiddens); // Output the dynamic tab headers $headerOptions = array('tabs' => array()); foreach ($tabHtml as $tab => $tabContent) { $alias = preg_replace('/[^a-zA-Z0-9]/', '', strtolower($tab)); $tabtitle = lang::get("LANG_Tab_{$alias}"); if ($tabtitle == "LANG_Tab_{$alias}") { // if no translation provided, we'll just use the standard heading $tabtitle = $tab; } $headerOptions['tabs']['#' . $alias] = $tabtitle; } if ($args['interface'] != 'one_page') { $r .= data_entry_helper::tab_header($headerOptions); data_entry_helper::enable_tabs(array('divId' => 'controls', 'style' => $args['interface'], 'progressBar' => isset($args['tabProgress']) && $args['tabProgress'] == true)); } // Output the dynamic tab content $pageIdx = 0; foreach ($tabHtml as $tab => $tabContent) { // get a machine readable alias for the heading $tabalias = preg_replace('/[^a-zA-Z0-9]/', '', strtolower($tab)); $r .= '<div id="' . $tabalias . '">' . "\n"; // For wizard include the tab title as a header. if ($args['interface'] != 'tabs') { $r .= '<h1>' . $headerOptions['tabs']['#' . $tabalias] . '</h1>'; } $r .= $tabContent; // Add any buttons required at the bottom of the tab if ($args['interface'] == 'wizard') { $r .= data_entry_helper::wizard_buttons(array('classRedisplay' => 'ui-widget-content ui-state-default ui-corner-all indicia-button tab-submit-redisplay', 'captionSaveRedisplay' => 'save and redisplay', 'divId' => 'controls', 'page' => $pageIdx === 0 ? 'first' : ($pageIdx == count($tabs) - 1 ? 'last' : 'middle'))); } elseif ($pageIdx == count($tabs) - 1 && !($args['interface'] == 'tabs' && $args['save_button_below_all_pages'])) { // last part of a non wizard interface must insert a save button, unless it is tabbed interface with save button beneath all pages $r .= "<input type=\"submit\" class=\"ui-state-default ui-corner-all\" value=\"" . lang::get('LANG_Save') . "\" />\n"; $r .= "<input type=\"submit\" name=\"navigate:newoccurrence\" class=\"ui-state-default ui-corner-all\" value=\"" . lang::get('LANG_Save_and_New') . "\" />\n"; $r .= "<input type=\"button\" class=\"ui-state-default ui-corner-all\"value=\"" . lang::get('LANG_Cancel') . "\" onclick=\"window.location.href='" . $cancelUrl . "'\" >\n"; } $pageIdx++; $r .= "</div>\n"; } $r .= "</div>\n"; if ($args['interface'] == 'tabs' && $args['save_button_below_all_pages']) { $r .= "<input type=\"submit\" class=\"ui-state-default ui-corner-all\" value=\"" . lang::get('LANG_Save') . "\" />\n"; $r .= "<input type=\"submit\" name=\"navigate:newoccurrence\" class=\"ui-state-default ui-corner-all\" value=\"" . lang::get('LANG_Save_and_New') . "\" />\n"; $r .= "<input type=\"button\" class=\"ui-state-default ui-corner-all\" value=\"" . lang::get('LANG_Cancel') . "\" onclick=\"window.location.href='" . $cancelUrl . "'\" >\n"; } if (!empty(data_entry_helper::$validation_errors)) { $r .= data_entry_helper::dump_remaining_errors(); } $r .= "</form>"; $url = self::$svcUrl . "/data/sample/" . data_entry_helper::$entity_to_load['sample:parent_id']; $url .= "?mode=json&view=detail&auth_token=" . self::$auth['read']['auth_token'] . "&nonce=" . self::$auth['read']['nonce']; $session = curl_init($url); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); $entity = json_decode(curl_exec($session), true); if (isset($entity['error'])) { throw new Exception($entity['error']); } data_entry_helper::$javascript .= "\n// Create a vector layer to display the supersample location\n// the default edit layer is used for the subsamples\nSSStyleMap = new OpenLayers.StyleMap({\n \"default\": new OpenLayers.Style({\n fillColor: \"Green\",\n strokeColor: \"Black\",\n fillOpacity: 0.2,\n strokeWidth: 1\n })\n });\nSSLayer = new OpenLayers.Layer.Vector(\"" . lang::get("LANG_Supersample_Layer") . "\",\n {styleMap: SSStyleMap});\nSSparser = new OpenLayers.Format.WKT();\nSSfeature = SSparser.read('" . $entity[0]['wkt'] . "');\nSSLayer.addFeatures([SSfeature]);\n"; // The map can get initialised an awful lot later (eg when the tab it is on is displayed). // It is therefore virtually impossible to zoom to this supersample in as the code is not templated return $r; }
protected static function tab_other_species($args, $auth) { $r = ''; $indicia_templates['taxon_label'] = '<div class="biota nobreak"><span class="vernacular">{common}</span>' . '<br/><span class="sci binomial"><em>{taxon}</em></span> {authority}</div>'; $extraParams = $auth['read']; $species_ctrl_opts = array('id' => "species-other", 'label' => 'Species', 'lookupListId' => $args['other_list_id'], 'cacheLookup' => isset($args['cache_lookup']) && $args['cache_lookup'], 'PHPtaxonLabel' => true, 'class' => 'checklist', 'survey_id' => $args['survey_id'], 'extraParams' => $extraParams, 'language' => 'eng', 'occAttrClasses' => array('coverage'), 'reloadExtraParams' => array('taxon_list_id' => $args['other_list_id']), 'speciesNameFilterMode' => 'excludeSynonyms', 'helpText' => 'Please provide details of any additional species you would like to record that you observed during your wildflower count. ' . 'Type the species name into the box on the left of the grid then select the correct name from the drop-down list of suggestions. ' . 'Make sure you input the information about whether the species was recorded on the path or linear/square transect.'); if (!empty($args['taxon_filter_field']) && !empty($args['taxon_filter'])) { $filterLines = helper_base::explode_lines($args['taxon_filter']); $species_ctrl_opts['taxonFilterField'] = $args['taxon_filter_field']; $species_ctrl_opts['taxonFilter'] = $filterLines; } self::build_grid_taxon_label_function($args); self::build_grid_autocomplete_function($args); $r .= data_entry_helper::species_checklist($species_ctrl_opts); $r .= '<p class="highlight">' . lang::get('Please review all tabs of the form before submitting the survey.') . '</p>'; $r .= data_entry_helper::wizard_buttons(array('divId' => 'tabs', 'page' => 'last', 'captionSave' => 'Submit')); return $r; }
/** * Return the generated form output. * @return Form HTML. */ public static function get_form($args) { global $user; $logged_in = $user->uid > 0; $r = "\n<form method=\"post\" id=\"entry_form\">\n"; // 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']; // 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"; } $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 .= "<div 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 .= "</div>\n"; } $r .= "<div id=\"species\">\n"; // Output all our hidden data here $r .= $auth['write']; if ($logged_in) { // If logged in, output some hidden data about the user $r .= iform_user_get_hidden_inputs($args); } $r .= "<input type=\"hidden\" id=\"website_id\" name=\"website_id\" value=\"" . $args['website_id'] . "\" />\n"; $r .= "<input type=\"hidden\" id=\"survey_id\" name=\"survey_id\" value=\"" . $args['survey_id'] . "\" />\n"; $r .= "<input type=\"hidden\" id=\"record_status\" name=\"record_status\" value=\"C\" />\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 .= "</div>\n"; $r .= "<div id=\"place\">\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::sref_and_system(array('label' => lang::get('sample:entered_sref'), 'systems' => $systems)); $r .= data_entry_helper::georeference_lookup(array('label' => lang::get('search for place on map'), 'georefPreferredArea' => $args['georefPreferredArea'], 'georefCountry' => $args['georefCountry'], 'georefLang' => $args['language'])); // retrieve options for the IndiciaMapPanel, and optionally options for OpenLayers. $options = iform_map_get_map_options($args, $readAuth); $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('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', 'resizeWidth' => 1024, 'resizeHeight' => 768, 'table' => 'occurrence_image')); // Dynamically create a control for the abundance $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 .= "</div>\n"; $r .= "</div>\n"; $r .= "</form>"; return $r; }