/** * This method is called ONLY after ALL validation has * passed. This is the method that allows you to * do something with the data, say insert/update records * in the DB. */ function form_action() { $success = true; $file = $this->get_element($this->getUploadFileLabel()); $fileInfo = $file->get_file_info(); $this->set_file_info($fileInfo); $this->set_file_info_table($fileInfo); // Read the file contents for processing $lines = file($fileInfo['tmp_name']); $line_number = 1; $record = array(); // Establish a database connection $sdifqueue = new SDIFResultsQueue(); // Need a record set to work with $rs = $sdifqueue->getEmptyRecordSet(); // Process each line in the file, adding it to the SDIF queue foreach ($lines as $line) { if (trim($line) == "") { continue; } $record_type = substr($line, 0, 2); $record["linenumber"] = $line_number; $record["recordtype"] = $record_type; $record["sdifrecord"] = trim($line); $sql = $sdifqueue->getConnection()->GetInsertSQL($rs, $record); $sdifqueue->setQuery($sql); $sdifqueue->runInsertQuery(); $line_number++; } unset($sdifqueue); // Delete the file so we don't keep a lot of stuff around. if (!unlink($fileInfo['tmp_name'])) { $this->add_error(html_div('ft-error-msg', $this->getUploadFileLabel(), 'Unable to remove uploaded file.')); } $this->set_action_message(html_div('ft-note-msg', 'File "' . $this->get_element_value($this->getUploadFileLabel()) . '" successfully uploaded.')); return $success; }