try { throw new Exception("MySQL error {$mysqli->error} <br /> Query:<br /> ", $mysqli->errno); } catch (Exception $e) { echo "Error No: " . $e->getCode() . " - " . $e->getMessage() . "<br />"; echo nl2br($e->getTraceAsString()); } } $addQuestion->bind_param('ssssssssisssssssissss', $q_type, $theme, $scenario, $leadin, $correct_fback, $incorrect_fback, $display_method, $notes, $userObject->get_user_ID(), $new_q_media, $q_media_width, $q_media_height, $bloom, $scenario_plain, $leadin_plain, $std, $new_status, $q_option_order, $score_method, $settings, $guid); $addQuestion->execute(); $new_qids[] = $question_id = $mysqli->insert_id; if ($q_type == 'enhancedcalc') { $calculation_qid_map[$q_id] = $question_id; } $addQuestion->close(); // Add in a record to the papers table. Paper_utils::add_question($new_paper_id, $question_id, $screen, $display_pos, $mysqli); // Create a track changes record to say where question was copied from. $logger = new Logger($mysqli); $logger->track_change('Copied Question', $question_id, $userObject->get_user_ID(), $question, $question_id, 'Copied Question'); // Create a track changes record to say new question added to paper. $logger->track_change('Paper', $new_paper_id, $userObject->get_user_ID(), '', $question_id, 'Add Question'); // Lookup and copy the keywords $keyword_result = $mysqli->prepare("SELECT keywordID FROM keywords_question WHERE q_id = ?"); $keyword_result->bind_param('i', $question); $keyword_result->execute(); $keyword_result->store_result(); $keyword_result->bind_result($keywordID); while ($keyword_result->fetch()) { $addKeyword = $mysqli->prepare("INSERT INTO keywords_question VALUES (?, ?)"); $addKeyword->bind_param('ii', $question_id, $keywordID); $addKeyword->execute();
// Get the maximum display position for an existing paper. $result = $mysqli->prepare("SELECT MAX(display_pos), MAX(screen) FROM papers WHERE paper = ?"); $result->bind_param('i', $property_id); $result->execute(); $result->bind_result($display_pos, $screen); $result->fetch(); $result->close(); if ($screen == '') { $screen = 1; } $display_pos++; // Add one to put new question right at the end. $q_IDs = explode(',', $q_id); for ($i = 1; $i < count($q_IDs); $i++) { $map_guid = array(); Paper_utils::add_question($property_id, $q_IDs[$i], $screen, $display_pos, $mysqli); $display_pos++; if ($map_outcomes) { // Make sure that paper is on the module we're copying from $paper_modules = $properties->get_modules(); if (in_array($_GET['module'], array_keys($paper_modules))) { if (isset($_POST['outcomes']) and $_POST['outcomes'] != '') { $outcomes = json_decode($_POST['outcomes'], true); $mappings = $mysqli->prepare("SELECT question_id, obj_id FROM relationships WHERE question_id = ? AND idMod = ?"); $mappings->bind_param('ii', $q_IDs[$i], $_GET['module']); $mappings->execute(); $mappings->store_result(); $mappings->bind_result($map_q_id, $obj_id); while ($mappings->fetch()) { if (isset($outcomes[$obj_id])) { $map_guid[$outcomes[$obj_id]] = true;
/** * * @author Simon Wilkinson * @version 1.0 * @copyright Copyright (c) 2014 The University of Nottingham * @package */ require '../../include/staff_auth.inc'; require_once '../../classes/paperutils.class.php'; require_once '../../classes/logger.class.php'; if ($_POST['questions_to_add'] != '') { $logger = new Logger($mysqli); $questions = explode(',', $_POST['questions_to_add']); $display_pos = $_GET['display_pos']; foreach ($questions as $item) { Paper_utils::add_question($_GET['paperID'], $item, $_POST['screen'], $display_pos, $mysqli); $display_pos++; // Create a track changes record to say new question added. $tmp_paperID = intval($_GET['paperID']); $success = $logger->track_change('Paper', $tmp_paperID, $userObject->get_user_ID(), '', $item, 'Add Question'); } } $mysqli->close(); $paperID = ''; $type = ''; $scrOfY = ''; $module = ''; $folder = ''; if (isset($_GET['paperID'])) { $paperID = $_GET['paperID']; }
/** * IMPORT: Decode the data file and add questions one by one to the current paper. */ private function load_raf_data() { $data_array = json_decode($this->data, true); $display_pos = 1; $this->raf_company = $data_array['metadata']['company']; foreach ($data_array['items'] as $item) { $q_id = $this->write_question($item['question']); $this->write_keywords($item['keywords'], $q_id); foreach ($item['options'] as $options) { $this->write_option($options, $q_id); } if (is_object($this->properties)) { $paperID = $this->properties->get_property_id(); $screen_no = $item['question']['screen']; Paper_utils::add_question($paperID, $q_id, $screen_no, $display_pos, $this->db); } $display_pos++; } }