/** * Return the generated form output. * @return Form HTML. */ public static function get_form($args, $node) { // Navigation Rules: URL contents: // 1) GET : Views Grid. From there we can EDIT an existing supersample (2) or add a new one (3) // 2) GET ?supersample_id=<x> : Views supersample with id=<x>: From here can cancel (1), POST changes to the supersample (4), view an existing occurrence (5) ar create a new occurrence (6) // 3) GET ?newsupersample : Views a form which allows the creation of a new supersample. No occurrences can be added until saved: occurrence grid not displayed. // From here can save the supersample details (4), or cancel - back to (1). // 4) POST : Supersample POST. sample:parent_id is not included in the POST. POST includes only sample or possibly location based information. No occurrence details. sample:parent_id is forced to null. // Navigation option: 1) Displays the same as (2), but has to fetch the most recent supersample ID for the user for a new one. // 2) Displays the same as (1) // 5) GET ?sample_id=<x> : Views the sample with id=<x>. From here can cancel (2), POST changes to the sample (7). // 6) POST [newsample] : Views a form which allows the creation of a new sample and its associated occurrence(s). The POST must contain the newsample - parent_id. // Displays a blank (5) -> From here can POST changes to the sample/occurrence details (7), or cancel - back to (2). // 7) POST : Sample POST. sample:parent_id is included in the POST. POST includes samples and occurrence information. No location. // Displays the same as (5), but has to fetch the most recent sample ID for the user for a new one. // Navigation option: 1) Displays the same as (5), but has to fetch the most recent sample ID for the user for a new one. // 2) Displays the same as (2), determined by posted sample:parent_id define("MODE_GRID", 1); define("MODE_EXISTING_SUPERSAMPLE", 2); define("MODE_NEW_SUPERSAMPLE", 3); define("MODE_POST_SUPERSAMPLE", 4); define("MODE_EXISTING_OCCURRENCE", 5); // Occurrences are actually sample/occurrence pair define("MODE_NEW_OCCURRENCE", 6); define("MODE_POST_OCCURRENCE", 7); self::parse_defaults($args); self::getArgDefaults($args); self::$gridmode = false; global $user; $logged_in = $user->uid > 0; $r = ''; if (!$logged_in) { // Return a login link that takes you back to this form when done. // TBD this language string needs sorting return lang::get('Before using this facility, please <a href="' . url('user/login', array('query' => 'destination=node/' . $node->nid)) . '">login</a> to the website.'); } // Get authorisation tokens to update and read from the Warehouse. self::$auth = data_entry_helper::get_read_write_auth($args['website_id'], $args['password']); self::$svcUrl = data_entry_helper::$base_url . '/index.php/services'; $mode = MODE_GRID; // default mode if ($_POST) { if (array_key_exists('sample:parent_id', $_POST)) { $mode = MODE_POST_OCCURRENCE; } else { if (array_key_exists('newsample_parent_id', $_POST)) { $mode = MODE_NEW_OCCURRENCE; } else { $mode = MODE_POST_SUPERSAMPLE; } } if (isset($_POST['gridmode'])) { self::$gridmode = true; } } else { if (array_key_exists('newSuperSample', $_GET)) { $mode = MODE_NEW_SUPERSAMPLE; } else { if (array_key_exists('sample_id', $_GET)) { $mode = MODE_EXISTING_OCCURRENCE; $loadedSampleId = $_GET['sample_id']; } else { if (array_key_exists('supersample_id', $_GET)) { // if done this way around because the report grid adds the supersample id to url when picking the subsample $mode = MODE_EXISTING_SUPERSAMPLE; } } } } if ($args['multiple_occurrence_mode'] == 'multi') { self::$gridmode = true; } // 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 self::$mode = $mode; self::$currentUrl = url('node/' . $node->nid); // default mode MODE_GRID : display grid of the samples to add a new one // or edit an existing one. return call_user_func(array(get_called_class(), 'get_form_mode_' . $mode), $args, $node); }