Example #1
0
 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;
 }