/** * 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) { require_once drupal_get_path('module', 'iform') . '/client_helpers/import_helper.php'; $auth = import_helper::get_read_write_auth($args['website_id'], $args['password']); 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 = array(); $presetLines = explode("\n", $args['presetSettings']); foreach ($presetLines as $preset) { $preset = explode('=', $preset); // skip any invalid data for the presets if (count($preset) == 2) { $presets[$preset[0]] = $preset[1]; } } $presets = array_merge(array('website_id' => $args['website_id'], 'password' => $args['password']), $presets); } else { $presets = array('website_id' => $args['website_id'], 'password' => $args['password']); } $r = import_helper::importer(array('model' => $model, 'auth' => $auth, 'presetSettings' => $presets)); return $r; }
/** * 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 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']); 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']); } $r = import_helper::importer(array('model' => $model, 'auth' => $auth, 'presetSettings' => $presets)); return $r; }
* * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program. If not, see http://www.gnu.org/licenses/gpl.html. * * @package Core * @subpackage Libraries * @author Indicia Team * @license http://www.gnu.org/licenses/gpl.html GPL * @link http://code.google.com/p/indicia/ */ /** * This is a view which outputs a parameters entry form to capture values that will apply to every row during an import, such as the website id. */ require_once DOCROOT . 'client_helpers/import_helper.php'; $auth = import_helper::get_read_write_auth(0 - $_SESSION['auth_user']->id, kohana::config('indicia.private_key')); echo import_helper::importer(array('model' => $this->controllerpath, 'auth' => $auth)); import_helper::$dumped_resources[] = 'jquery'; import_helper::$dumped_resources[] = 'jquery-ui'; echo import_helper::dump_javascript(); ?>
protected function submit_data_if_new_parent_sample_required(&$values, $data, $args, $writeAuth, $occurrenceNumber, &$submission) { //There are 2 arrays we are dealing with. $_POST contains the name of the column as a key and then the format //of the key required for submission as its value. The $data array is a numbered list of columns with a data //value. So in order to submit to the database, we need to use the $_POST data value as the key and the value from the $data //array as the value. The two arrays match up with each other e.g. the second item in the $_POST array relates to the //second item in the data array. So by counting as we look at each item in the $_POST array, we can then get the equivalent //item in the $data array as required. $postCounter = 0; //Assume to start with that we are going to use the parent sample from the previous row. $newSampleRequired = false; foreach ($_POST as $fieldName => $fieldInPostFormat) { //Check if any of the sample attributes have changed and also data held in the sample row in the database (as opposed to data held in the sample_attributes table) if ($fieldInPostFormat == 'sample:entered_sref' || $fieldInPostFormat == 'sample:date' || $fieldInPostFormat == 'sample:comment' || $fieldInPostFormat == 'sample:location_name' || substr($fieldInPostFormat, 0, 8) === "smpAttr:") { if (!empty($values[$fieldInPostFormat]) && $values[$fieldInPostFormat] != $data[$postCounter]) { $newSampleRequired = true; } } //For the Site we submit an id rather than the raw name. if ($fieldName == 'Site') { //If there is no main location, this is still a valid scenerio as there can be an "Other Site" if (empty($data[$postCounter])) { $values['sample:location_id'] = ''; } else { $readAuth = data_entry_helper::get_read_auth($args['website_id'], $args['password']); $locationRecord = data_entry_helper::get_population_data(array('table' => 'location', 'extraParams' => $readAuth + array('name' => $data[$postCounter]))); //If we can't find an id for the location name in the database, then warn the user. if (!empty($locationRecord[0]['id'])) { //Still need to do the same check for location_id to see if it has changed from the previous row. if (!empty($values['sample:location_id']) && $values['sample:location_id'] != $locationRecord[0]['id']) { $newSampleRequired = true; } $values['sample:location_id'] = $locationRecord[0]['id']; } else { drupal_set_message('<B>Warning: The location ' . $data[$postCounter] . ' is not currently present in the database. .</B>'); if ($args['keep_going_after_error']) { drupal_set_message('<i>I will attempt to continue with the import but errors may occur or there might be inconsistent data entered into the database.</i>'); } else { drupal_set_message('<i>The import has been stopped.</i>'); } return array($occurrenceNumber, true); } } } //Move onto the next column. $postCounter++; } if ($newSampleRequired === true) { $submission = self::get_submission($values, $args, true); $authentication = import_helper::get_read_write_auth($args['website_id'], $args['password']); $response = data_entry_helper::forward_post_to('save', $submission, $authentication['write_tokens']); //Once we know we need a new sample, we start building the values array again. $occurrenceNumber = 0; $values = array(); self::get_initial_values_array_values($values, $args); } return array($occurrenceNumber, false); }