/** * Return the generated form output. * @param array $args List of parameter values passed through to the form depending on how the form has been configured. * This array always contains a value for language. * @param object $node The Drupal node object. * @param array $response When this form is reloading after saving a submission, contains the response from the service call. * Note this does not apply when redirecting (in this case the details of the saved object are in the $_GET data). * @return Form HTML. */ public static function get_form($args, $node, $response = null) { if (empty($_GET['group_id'])) { return 'This page needs a group_id URL parameter.'; } global $base_url; global $user; iform_load_helpers(array('data_entry_helper')); data_entry_helper::$javascript .= "indiciaData.nodeId=" . $node->nid . ";\n"; data_entry_helper::$javascript .= "indiciaData.baseUrl='" . $base_url . "';\n"; data_entry_helper::$javascript .= "indiciaData.currentUsername='******';\n"; //Translations for the comment that goes into occurrence_comments when a record is verified or rejected. data_entry_helper::$javascript .= 'indiciaData.verifiedTranslation = "' . lang::get('Verified') . "\";\n"; data_entry_helper::$javascript .= 'indiciaData.rejectedTranslation = "' . lang::get('Rejected') . "\";\n"; self::$auth = data_entry_helper::get_read_write_auth($args['website_id'], $args['password']); group_authorise_form($args, self::$auth['read']); $group = data_entry_helper::get_population_data(array('table' => 'group', 'extraParams' => self::$auth['read'] + array('id' => $_GET['group_id'], 'view' => 'detail'))); $group = $group[0]; hostsite_set_page_title("{$group['title']}: {$node->title}"); $def = json_decode($group['filter_definition'], true); $defstring = ''; // reconstruct this as a string to feed into dynamic report explorer foreach ($def as $key => $value) { if ($key) { $value = is_array($value) ? json_encode($value) : $value; $defstring .= "{$key}={$value}\n"; if ($key === 'indexed_location_id' || $key === 'indexed_location_list' || $key === 'location_id' || $key === 'location_list') { $args['location_boundary_id'] = $value; } elseif (($key === 'taxon_group_id' || $key === 'taxon_group_list') && strpos($value, ',') === FALSE) { // if the report is locked to a single taxon group, then we don't need taxonomy columns. $args['skipped_report_columns'] = array('taxon_group', 'taxonomy'); } } } if (empty($_GET['implicit'])) { // no need for a group user filter $args['param_presets'] = implode("\n", array($args['param_presets'], $defstring)); } else { // filter to group users - either implicitly, or only if they explicitly submitted to the group $prefix = $_GET['implicit'] === 'true' || $_GET['implicit'] === 't' ? 'implicit_' : ''; // add the group parameters to the preset parameters passed to all reports on this page $args['param_presets'] = implode("\n", array($args['param_presets'], $defstring, "{$prefix}group_id=" . $_GET['group_id'])); } $args['param_presets'] .= "\n"; if (!empty($args['hide_standard_param_filter'])) { data_entry_helper::$javascript .= "\$('#standard-params').hide();\n"; } return parent::get_form($args, $node); }
/** * Return the Indicia form code * @param array $args Input parameters. * @param array $node Drupal node object * @param array $response Response from Indicia services after posting a verification. * @return HTML string */ public static function get_form($args, $node, $response) { iform_load_helpers(array('import_helper')); $auth = import_helper::get_read_write_auth($args['website_id'], $args['password']); group_authorise_form($args, $auth['read']); if ($args['model'] == 'url') { if (!isset($_GET['type'])) { return "This form is configured so that it must be called with a type parameter in the URL"; } $model = $_GET['type']; } else { $model = $args['model']; } if (isset($args['presetSettings'])) { $presets = get_options_array_with_user_data($args['presetSettings']); $presets = array_merge(array('website_id' => $args['website_id'], 'password' => $args['password']), $presets); } else { $presets = array('website_id' => $args['website_id'], 'password' => $args['password']); } if (!empty($_GET['group_id'])) { // loading data into a recording group. $group = data_entry_helper::get_population_data(array('table' => 'group', 'extraParams' => $auth['read'] + array('id' => $_GET['group_id'], 'view' => 'detail'))); $group = $group[0]; $presets['sample:group_id'] = $_GET['group_id']; hostsite_set_page_title(lang::get('Import data into the {1} group', $group['title'])); // if a single survey specified for this group, then force the data into the correct survey $filterdef = json_decode($group['filter_definition'], true); if (!empty($filterdef['survey_list_op']) && $filterdef['survey_list_op'] === 'in' && !empty($filterdef['survey_list'])) { $surveys = explode(',', $filterdef['survey_list']); if (count($surveys) === 1) { $presets['survey_id'] = $surveys[0]; } } } try { $r = import_helper::importer(array('model' => $model, 'auth' => $auth, 'presetSettings' => $presets)); } catch (Exception $e) { hostsite_show_message($e->getMessage(), 'warning'); $reload = import_helper::get_reload_link_parts(); unset($reload['params']['total']); unset($reload['params']['uploaded_csv']); $reloadpath = $reload['path'] . '?' . import_helper::array_to_query_string($reload['params']); $r = "<p>" . lang::get('Would you like to ') . "<a href=\"{$reloadpath}\">" . lang::get('import another file?') . "</a></p>"; } 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) { if (empty($_GET['group_id'])) { return 'This page needs a group_id URL parameter.'; } require_once 'includes/map.php'; require_once 'includes/groups.php'; global $indicia_templates; iform_load_helpers(array('report_helper', 'map_helper')); $conn = iform_get_connection_details($node); $readAuth = report_helper::get_read_auth($conn['website_id'], $conn['password']); report_helper::$javascript .= "indiciaData.website_id={$conn['website_id']};\n"; report_helper::$javascript .= "indiciaData.nodeId={$node->nid};\n"; group_authorise_form($args, $readAuth); $group = data_entry_helper::get_population_data(array('table' => 'group', 'extraParams' => $readAuth + array('id' => $_GET['group_id'], 'view' => 'detail'))); $group = $group[0]; hostsite_set_page_title("{$group['title']}: {$node->title}"); $actions = array(); if (!empty($args['edit_location_path'])) { $actions[] = array('caption' => 'edit', 'url' => '{rootFolder}' . $args['edit_location_path'], 'urlParams' => array('group_id' => $_GET['group_id'], 'location_id' => '{location_id}')); } $actions[] = array('caption' => 'remove', 'javascript' => "remove_location_from_group({groups_location_id});"); $leftcol = report_helper::report_grid(array('readAuth' => $readAuth, 'dataSource' => 'library/locations/locations_for_groups', 'sendOutputToMap' => true, 'extraParams' => array('group_id' => $_GET['group_id']), 'rowId' => 'location_id', 'columns' => array(array('display' => 'Actions', 'actions' => $actions, 'caption' => 'edit', 'url' => '{rootFolder}')))); $leftcol .= '<fieldset><legend>' . lang::Get('Add sites to the group') . '</legend>'; $leftcol .= '<p>' . lang::get('LANG_Add_Sites_Instruct') . '</p>'; if (!empty($args['edit_location_path'])) { $leftcol .= lang::get('Either') . ' <a class="button" href="' . hostsite_get_url($args['edit_location_path'], array('group_id' => $_GET['group_id'])) . '">' . lang::get('enter details of a new site') . '</a><br/>'; } $leftcol .= data_entry_helper::select(array('label' => lang::get('Or, add an existing site'), 'fieldname' => 'add_existing_location_id', 'report' => 'library/locations/locations_available_for_group', 'caching' => false, 'blankText' => lang::get('<please select>'), 'valueField' => 'location_id', 'captionField' => 'name', 'extraParams' => $readAuth + array('group_id' => $_GET['group_id'], 'user_id' => hostsite_get_user_field('indicia_user_id', 0)), 'afterControl' => '<button id="add-existing">Add</button>')); $leftcol .= '</fieldset>'; // @todo Link existing My Site to group. Need a new report to list sites I created, with sites already in the group // removed. Show in a drop down with an add button. Adding must create the groups_locations record, plus refresh // the grid and refresh the drop down. // @todo set destination after saving added site $map = map_helper::map_panel(iform_map_get_map_options($args, $readAuth), iform_map_get_ol_options($args)); $r = str_replace(array('{col-1}', '{col-2}'), array($leftcol, $map), $indicia_templates['two-col-50']); data_entry_helper::$javascript .= "indiciaData.group_id={$_GET['group_id']};\n"; return $r; }
/** * Override get_form_html so we can store the remembered argument in a global, to make * it available to a hook function which exists outside the form. */ protected static function get_form_html($args, $auth, $attributes) { group_authorise_form($args, $auth['read']); // We always want an autocomplete formatter function for species lookups. The form implementation can // specify its own if required if (method_exists(self::$called_class, 'build_grid_autocomplete_function')) { call_user_func(array(self::$called_class, 'build_grid_autocomplete_function'), $args); } else { $opts = array('cacheLookup' => $args['cache_lookup'], 'speciesIncludeBothNames' => $args['species_include_both_names'], 'speciesIncludeTaxonGroup' => $args['species_include_taxon_group'], 'speciesIncludeIdDiff' => $args['species_include_id_diff']); data_entry_helper::build_species_autocomplete_item_function($opts); } global $remembered; $remembered = isset($args['remembered']) ? $args['remembered'] : ''; if (empty(data_entry_helper::$entity_to_load['sample:group_id']) && !empty($_GET['group_id'])) { data_entry_helper::$entity_to_load['sample:group_id'] = $_GET['group_id']; } if (!empty(data_entry_helper::$entity_to_load['sample:group_id'])) { self::$group = data_entry_helper::get_population_data(array('table' => 'group', 'extraParams' => $auth['read'] + array('view' => 'detail', 'id' => data_entry_helper::$entity_to_load['sample:group_id']))); self::$group = self::$group[0]; $filterdef = json_decode(self::$group['filter_definition']); // does the group filter define a site or boundary for the recording? If so we need to show it and limit the map extent $locationIDToLoad = empty($filterdef->location_id) ? empty($filterdef->indexed_location_id) ? false : $filterdef->indexed_location_id : $filterdef->location_id; if ($locationIDToLoad) { $response = data_entry_helper::get_population_data(array('table' => 'location', 'extraParams' => $auth['read'] + array('id' => $locationIDToLoad, 'view' => 'detail'))); $geom = $response[0]['boundary_geom'] ? $response[0]['boundary_geom'] : $response[0]['centroid_geom']; iform_map_zoom_to_geom($geom, lang::get('Boundary of {1} for the {2} group', $response[0]['name'], self::$group['title']), true); self::hide_other_boundaries($args); } elseif (!empty($filterdef->searchArea)) { iform_map_zoom_to_geom($filterdef->searchArea, lang::get('Recording area for the {1} group', self::$group['title']), true); self::hide_other_boundaries($args); } if (!empty($filterDef->taxon_group_names)) { $args['taxon_filter'] = implode("\n", array_values((array) $filterdef->taxon_group_names)); $args['taxon_filter_field'] = 'taxon_group'; } // @todo Consider other types of species filter, e.g. family or species list? } return parent::get_form_html($args, $auth, $attributes); }