/** * 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; }