Пример #1
0
 /**
  * Insert a question exclusion record into the database.
  */
 public function add_exclusion($q_id, $status)
 {
     $userObj = UserObject::get_instance();
     if ($result = $this->db->prepare("INSERT INTO question_exclude VALUES (NULL, ?, ?, ?, {$userObj->get_user_ID()}, NOW(), '')")) {
         $result->bind_param('iis', $this->paper_id, $q_id, $status);
         $result->execute();
         $result->close();
     } else {
         display_error("Question_exclude Insert Error 1", $this->db->error);
     }
 }
Пример #2
0
 static function sms_api($data)
 {
     global $mysqli;
     if ($data[0] != 'SMS') {
         return '';
     }
     $SMS = SmsUtils::GetSmsUtils();
     if ($SMS === false) {
         $configObject = Config::get_instance();
         $notice = UserNotices::get_instance();
         $userObject = UserObject::get_instance();
         $userid = 0;
         $username = '******';
         if (isset($userObject)) {
             $userid = $userObject->get_user_ID();
             $username = $userObject->get_username();
         }
         $error_type = 'Notice';
         $errstr = 'ROGO:SMS not correctly setup';
         $errfile = 'lti_integration.php';
         if (is_null($configObject->get('cfg_db_port'))) {
             $configObject->set('cfg_db_port', 3306);
         }
         // Query may fail if we try to insert while another statement is open.
         // Since we don't have a handle on the original statement, create another DB link
         $mysqli2 = DBUtils::get_mysqli_link($configObject->get('cfg_db_host'), $configObject->get('cfg_db_username'), $configObject->get('cfg_db_passwd'), $configObject->get('cfg_db_database'), $configObject->get('cfg_db_charset'), $notice, $configObject->get('dbclass'), $configObject->get('cfg_db_port'));
         $log_error = $mysqli2->prepare("INSERT INTO sys_errors VALUES(NULL, NOW(), ?, ?, ?, ?, ?, ?, NULL, ?, ?, ?, ?, ?, ?, ?)");
         $log_error->bind_param('issssssssisss', $userid, $username, $error_type, $errstr, $errfile, $errline, $_SERVER['PHP_SELF'], $_SERVER['QUERY_STRING'], $_SERVER['REQUEST_METHOD'], $paperID, $post_data, $variables, $backtrace);
         $log_error->execute();
         $log_error->close();
         return '';
     } else {
         $SMS->set_module($data[2]);
         return $SMS->url;
     }
 }
Пример #3
0
*
* Rogō hompage. Uses ../include/options_menu.inc for the sidebar menu.
*
* @author Simon Wilkinson
* @version 1.0
* @copyright Copyright (c) 2014 The University of Nottingham
* @package
*/
require_once '../include/staff_student_auth.inc';
require_once '../include/errors.inc';
require_once '../include/sidebar_menu.inc';
require_once '../classes/recyclebin.class.php';
require_once '../config/index.inc';
require_once '../classes/paperutils.class.php';
require_once '../classes/folderutils.class.php';
$userObject = UserObject::get_instance();
// Redirect Students (if not also staff), External Examiners and Invigilators to their own areas.
if ($userObject->has_role('Student') and !$userObject->has_role(array('Staff', 'Admin', 'SysAdmin'))) {
    header("location: ../students/");
    exit;
} elseif ($userObject->has_role('External Examiner')) {
    header("location: ../reviews/");
    exit;
} elseif ($userObject->has_role('Invigilator')) {
    header("location: ../invigilator/");
    exit;
}
// If we're still here we should be staff
require_once '../include/staff_auth.inc';
?>
<!DOCTYPE html>
 /**
  * Change the correct answer after the question has been locked. Update user marks in summative log table
  * @param mixed $new_correct Array of new values for fields that can be corrected
  * @param integer $paper_id
  * @param boolean $changes True if changes have been made by a previous corrector
  * @param integer $paper_type Integer index for type of paper
  * @return array[$string] Any errors encountered in the correction process
  */
 public function execute($new_correct, $paper_id, &$changes, $paper_type)
 {
     $errors = array();
     $marks_correct = $this->_question->get_marks_correct();
     $marks_incorrect = $this->_question->get_marks_incorrect();
     $marks_partial = $this->_question->get_marks_partial();
     $tolerance_full = $this->_question->get_tolerance_full();
     if ($tolerance_full != $new_correct['tolerance_full']) {
         $this->_question->set_tolerance_full($new_correct['tolerance_full']);
         $changes = true;
         $this->_question->add_unified_field_modification('tolerance_full', 'tolerance_full', $tolerance_full, $new_correct['tolerance_full'], $this->_lang_strings['postexamchange']);
     }
     $tolerance_partial = $this->_question->get_tolerance_partial();
     if ($tolerance_partial != $new_correct['tolerance_partial']) {
         $this->_question->set_tolerance_partial($new_correct['tolerance_partial']);
         $changes = true;
         $this->_question->add_unified_field_modification('tolerance_partial', 'tolerance_partial', $tolerance_partial, $new_correct['tolerance_partial'], $this->_lang_strings['postexamchange']);
     }
     $answer_precision = $this->_question->get_answer_precision();
     if ($answer_precision != $new_correct['answer_precision']) {
         $this->_question->set_answer_precision($new_correct['answer_precision']);
         $changes = true;
         $this->_question->add_unified_field_modification('answer_precision', 'answer_precision', $answer_precision, $new_correct['answer_precision'], $this->_lang_strings['postexamchange']);
     }
     $strict_zeros = $this->_question->get_strict_zeros();
     // Need to be careful of how the correction code builds the values for check boxes
     if (isset($new_correct['strict_zeros'])) {
         $new_strict_zeros = is_array($new_correct['strict_zeros']) ? $new_correct['strict_zeros'][0] : $new_correct['strict_display'];
     } else {
         $new_strict_zeros = false;
     }
     if ($strict_zeros != $new_strict_zeros) {
         $this->_question->set_strict_zeros($new_strict_zeros);
         $changes = true;
         $this->_question->add_unified_field_modification('strict_zeros', 'strict_zeros', $strict_zeros, $new_strict_zeros, $this->_lang_strings['postexamchange']);
     }
     // Parse answers
     $opts = $this->_question->options;
     for ($i = 1; $i <= $this->_question->max_options; $i++) {
         if (isset($opts[$i])) {
             $ans = $opts[$i]->get_formula();
             $units = $opts[$i]->get_units();
             if ($ans != '' and $new_correct['option_formula'][$i - 1] == '') {
                 $opts[$i]->set_formula('');
                 $opts[$i]->set_units('');
                 $changes = true;
                 $this->_question->add_unified_field_modification('Deleted Answer ' . $i, 'Deleted Answer ' . $i, $ans . ', ' . $units, '', $this->_lang_strings['postexamchange']);
             } else {
                 if ($ans != $new_correct['option_formula'][$i - 1]) {
                     $opts[$i]->set_formula($new_correct['option_formula'][$i - 1]);
                     $changes = true;
                     if ($ans != '') {
                         $this->_question->add_unified_field_modification('option_formula' . $i, 'option_formula' . $i, $ans, $new_correct['option_formula'][$i - 1], $this->_lang_strings['postexamchange']);
                     }
                 }
                 if ($units != $new_correct['option_units'][$i - 1]) {
                     $opts[$i]->set_units($new_correct['option_units'][$i - 1]);
                     $changes = true;
                     if ($ans != '') {
                         $this->_question->add_unified_field_modification('option_units' . $i, 'option_units' . $i, $units, $new_correct['option_units'][$i - 1], $this->_lang_strings['postexamchange']);
                     }
                 }
                 if ($ans == '') {
                     $this->_question->add_unified_field_modification('New Answer ' . $i, 'New Answer ' . $i, '', $new_correct['option_formula'][$i - 1] . ', ' . $new_correct['option_units'][$i - 1], $this->_lang_strings['postexamchange']);
                 }
             }
         } elseif ($new_correct['option_formula'][$i - 1] != '') {
             // Complete new answer
             $changes = true;
             $userObj = UserObject::get_instance();
             $this->_question->options[$i] = new OptionENHANCEDCALC($this->_mysqli, $userObj->get_user_ID(), $this->_question, $i, $this->_lang_strings, array('formula' => $new_correct['option_formula'][$i - 1], 'units' => $new_correct['option_units'][$i - 1]));
             $this->_question->add_unified_field_modification('New Answer ' . $i, 'New Answer ' . $i, '', $new_correct['option_formula'][$i - 1] . ', ' . $new_correct['option_units'][$i - 1], $this->_lang_strings['postexamchange']);
         }
     }
     if ($changes) {
         try {
             if (!$this->_question->save()) {
                 $errors[] = $this->_lang_strings['datasaveerror'];
             } else {
                 enhancedcalc_remark($paper_type, $paper_id, $this->_question->id, $this->_question->get_settings(), $this->_mysqli, 'all');
             }
         } catch (ValidationException $vex) {
             $errors[] = $vex->getMessage();
         }
         if (count($errors) == 0) {
             $this->invalidate_paper_cache($paper_id);
         }
     }
     return $errors;
 }
Пример #5
0
 public static function paper_types($idMod, $show_retired, $db)
 {
     $userObject = UserObject::get_instance();
     $paper_types = array();
     if ($idMod == '0') {
         // Unused papers.
         if ($show_retired) {
             $sql = 'SELECT DISTINCT paper_type, COUNT(properties.property_id)
          FROM properties LEFT JOIN properties_modules
          ON properties.property_id = properties_modules.property_id
          WHERE idMod IS NULL
          AND paper_ownerID = ?
          AND deleted IS NULL
          GROUP BY paper_type
          ORDER BY paper_type';
         } else {
             $sql = 'SELECT DISTINCT paper_type, COUNT(properties.property_id)
          FROM properties LEFT JOIN properties_modules
          ON properties.property_id = properties_modules.property_id
          WHERE idMod IS NULL
          AND paper_ownerID = ?
          AND deleted IS NULL
          AND retired IS NULL
          GROUP BY paper_type
          ORDER BY paper_type';
         }
         $result = $db->prepare($sql);
         $result->bind_param('i', $userObject->get_user_ID());
     } else {
         if ($show_retired) {
             $sql = 'SELECT DISTINCT paper_type, COUNT(properties.property_id)
          FROM properties, properties_modules
          WHERE properties.property_id = properties_modules.property_id
          AND idMod = ?
          AND deleted IS NULL
          GROUP BY paper_type
          ORDER BY paper_type';
         } else {
             $sql = 'SELECT DISTINCT paper_type, COUNT(properties.property_id)
          FROM properties, properties_modules
          WHERE properties.property_id = properties_modules.property_id
          AND idMod = ?
          AND deleted IS NULL
          AND retired IS NULL
          GROUP BY paper_type
          ORDER BY paper_type';
         }
         $result = $db->prepare($sql);
         $result->bind_param('i', $idMod);
     }
     $result->execute();
     $result->bind_result($type, $number);
     while ($result->fetch()) {
         $paper_types[$type] = $number;
     }
     $result->close();
     return $paper_types;
 }
Пример #6
0
 function LoadQuestion($q_id)
 {
     global $REPLACEMEuserIDold, $show_debug;
     $userObj = UserObject::get_instance();
     // storage for question data
     $q_row = array();
     $o_rows = array();
     // retrieve question row from database
     $db = new Database();
     $db->SetTable('questions');
     $db->AddField('*');
     $db->AddWhere('q_id', $q_id, 'i');
     $q_row = $db->GetSingleRow();
     // retrieve array of options from database
     $db = new Database();
     $db->SetTable('options');
     $db->AddField('*');
     $db->AddWhere('o_id', $q_id, 'i');
     $db->AddOrder('id_num');
     $o_rows = $db->GetMultiRow();
     // determine q type and create a storage class for correct type
     $q_type = $q_row['q_type'];
     $q_storage = 'ST_Question_' . $q_type;
     $store = new $q_storage();
     $store->type = $q_type;
     // populate base storage fields
     $this->LoadQuestionBase($store, $q_row, $o_rows);
     // populate class specific storage fields
     $funcname = 'LoadQuestion' . $q_type;
     call_user_func(array($this, $funcname), $store, $q_row, $o_rows);
     // display some debug data
     print_p($q_row);
     print_p($o_rows, true, 100);
     // insert track changes record
     if ($show_debug != true) {
         $track = array();
         $track['type'] = "QTI Export";
         $track['typeID'] = $q_row['q_id'];
         $track['editor'] = $userObj->get_user_ID();
         $track['new'] = "Exported to QTI file";
         $track['part'] = "all";
         $track['changed'] = date("Y-m-d H:i:s");
         $db->InsertRow("track_changes", "id", $track);
     }
     // return question
     return $store;
 }
Пример #7
0
function marks_from_file($fileName, $paperID, $string, $properties, $db)
{
    $configObject = Config::get_instance();
    $configObject->get('cfg_tmpdir');
    $userObject = UserObject::get_instance();
    // Get properties of the paper.
    $session = $properties->get_calendar_year();
    $paper_date = $properties->get_raw_start_date();
    $moduleIDs = Paper_utils::get_modules($paperID, $db);
    // Get the questions on the paper.
    $paper = array();
    $question_no = 0;
    $result = $db->prepare("SELECT question, sum(marks_correct) AS sum FROM papers, options WHERE paper = ? AND papers.question = options.o_id GROUP BY question ORDER BY screen, display_pos");
    $result->bind_param('i', $paperID);
    $result->execute();
    $result->bind_result($question, $marks_correct);
    while ($result->fetch()) {
        $question_no++;
        $paper[$question_no]['id'] = $question;
        $paper[$question_no]['marks_correct'] = $marks_correct;
    }
    $result->close();
    // Get student data.
    $students = array();
    $modids = implode(',', array_keys($moduleIDs));
    $result = $db->prepare("SELECT users.id, student_id, username, yearofstudy, grade, title, surname, first_names FROM users, sid, modules_student WHERE users.id = sid.userID AND users.id = modules_student.userID AND idMod IN ({$modids}) AND calendar_year = ?");
    $result->bind_param('s', $session);
    $result->execute();
    $result->bind_result($id, $student_id, $username, $year, $grade, $title, $surname, $first_names);
    while ($result->fetch()) {
        $students[$student_id]['username'] = $username;
        $students[$student_id]['title'] = $title;
        $students[$student_id]['surname'] = $surname;
        $students[$student_id]['first_names'] = $first_names;
        $students[$student_id]['year'] = $year;
        $students[$student_id]['grade'] = $grade;
        $students[$student_id]['id'] = $id;
    }
    $result->close();
    $lines = file($fileName);
    $line_written = 0;
    echo "<table cellspacing=\"0\" cellpadding=\"2\" border=\"0\" style=\"margin-left:10px; border-collapse:collapse\">\n";
    foreach ($lines as $separate_line) {
        $error = '';
        if ($line_written == 0 and isset($_POST['header_row']) and $_POST['header_row'] == 1) {
            // Write out the header line.
            $fields = explode(',', $separate_line);
            echo "<tr><th></th><th colspan=\"3\">Student Name</th>";
            foreach ($fields as $field) {
                if (trim($field) != '') {
                    echo "<th>{$field}</th>";
                }
            }
            echo "</tr>\n";
        }
        if (!isset($_POST['header_row']) or $_POST['header_row'] != 1 or $line_written > 0) {
            $fields = explode(',', $separate_line);
            $sid = trim($fields[0]);
            if (!isset($students[$sid]['username'])) {
                // Student is not in class List.
                // Look up to see if anywhere else in Authentication database.
                $result = $db->prepare("SELECT id, student_id, users.username, yearofstudy, grade, title, surname, first_names FROM users, sid WHERE users.id = sid.userID AND sid.student_id = ?");
                $result->bind_param('s', $sid);
                $result->execute();
                $result->store_result();
                $result->bind_result($id, $student_id, $username, $year, $grade, $title, $surname, $first_names);
                if ($result->num_rows > 0) {
                    $result->fetch();
                    $students[$student_id]['username'] = $username;
                    $students[$student_id]['title'] = $title;
                    $students[$student_id]['surname'] = $surname;
                    $students[$student_id]['first_names'] = $first_names;
                    $students[$student_id]['year'] = $year;
                    $students[$student_id]['grade'] = $grade;
                    $students[$student_id]['id'] = $id;
                }
                $result->close();
            }
            if (isset($students[$sid]) and $students[$sid]['username'] != '') {
                // Student is in class List.
                $save_ok = true;
                $db->autocommit(false);
                $result = $db->prepare("SELECT id FROM log_metadata WHERE userID = ? AND paperID = ? AND started = ?");
                $result->bind_param('iis', $students[$sid]['id'], $paperID, $paper_date);
                $result->execute();
                $result->store_result();
                $result->bind_result($lmd_id);
                if ($result->num_rows > 0) {
                    $result->fetch();
                    $delete1 = $db->prepare("DELETE FROM log5 WHERE metadataID = ?");
                    $delete1->bind_param('i', $lmd_id);
                    $res = $delete1->execute();
                    if ($res == false) {
                        $save_ok = false;
                    }
                    $delete1->close();
                    if ($save_ok) {
                        $delete2 = $db->prepare("DELETE FROM log_metadata WHERE id = ?");
                        $delete2->bind_param('i', $lmd_id);
                        $res = $delete2->execute();
                        if ($res == false) {
                            $save_ok = false;
                        }
                        $delete2->close();
                    }
                }
                $result->close();
                //
                // did the all the save to log operations succeed?
                //
                if ($save_ok === false) {
                    //NO - rollback
                    $db->rollback();
                    $error = $string['errorsaving'];
                    break;
                } else {
                    //YES - commit the updates to the log tables
                    $db->commit();
                }
                $result = $db->prepare("INSERT INTO log_metadata (userID, paperID, started, ipaddress, student_grade, year, attempt) " . "VALUES (?, ?, ?, ?, ?, ?, ?)");
                $ip = '127.0.0.1';
                $attempt = 1;
                $result->bind_param('iisssii', $students[$sid]['id'], $paperID, $paper_date, $ip, $students[$sid]['grade'], $students[$sid]['year'], $attempt);
                $res = $result->execute();
                if ($res == false) {
                    $save_ok = false;
                } else {
                    $lmd_id = $db->insert_id;
                }
                $result->close();
                if ($save_ok) {
                    echo "<tr><td><img src=\"../artwork/green_plus_16.png\" wodth=\"16\" height=\"16\" alt=\"Add\" /></td><td>" . $students[$sid]['title'] . "</td><td>" . $students[$sid]['surname'] . "</td><td>" . $students[$sid]['first_names'] . "</td><td>{$sid}</td>";
                    for ($q = 1; $q <= $question_no; $q++) {
                        $result = $db->prepare("INSERT INTO log5 (q_id, mark, adjmark, totalpos, metadataID) VALUES (?, ?, ?, ?, ?)");
                        $mark = trim($fields[$q]);
                        if ($mark > $paper[$q]['marks_correct']) {
                            $save_mark = NULL;
                        } else {
                            $save_mark = floatval($mark);
                        }
                        $result->bind_param('iddii', $paper[$q]['id'], $save_mark, $save_mark, $paper[$q]['marks_correct'], $lmd_id);
                        $res = $result->execute();
                        if ($res == false) {
                            echo "<td>error</td>";
                            $save_ok = false;
                            break;
                        } else {
                            if ($mark > $paper[$q]['marks_correct']) {
                                echo '<td class="failed">too high</td>';
                            } elseif ($mark === '') {
                                echo '<td class="failed">missing</td>';
                            } else {
                                echo "<td class=\"num\">{$mark}</td>";
                            }
                        }
                        $result->close();
                    }
                    echo "</tr>\n";
                }
                //
                // did the all the save to log operations succeed?
                //
                if ($save_ok === false) {
                    //NO - rollback
                    $db->rollback();
                    $error = $string['errorsaving'];
                    break;
                } else {
                    //YES - commit the updates to the log tables
                    $db->commit();
                }
            } else {
                echo "<tr><td><img src=\"../artwork/red_cross_16.png\" wodth=\"16\" height=\"16\" alt=\"Failed\" /></td><td colspan=\"3\" class=\"failed\">Student not found.</td><td>{$sid}</td><td colspan=\"" . $question_no . "\" class=\"failed\">&nbsp;</td></tr>";
            }
        }
        $line_written++;
    }
    //if ($error != '') {
    //  echo "<li style=\"color:C00000\">$error</li>";
    //}
    echo "</table>\n";
    //turn auto commit back on so future queries function as before
    $db->autocommit(true);
}
Пример #8
0
 public function save()
 {
     $configObject = Config::get_instance();
     $userObject = UserObject::get_instance();
     if ($this->summative_lock and !$userObject->has_role('SysAdmin')) {
         // For SysAdmin drop through to bottom if
         $result = $this->db->prepare("UPDATE properties SET marking = ?, pass_mark = ?, distinction_mark = ?, display_correct_answer = ?, display_students_response = ?, display_question_mark = ?, display_feedback = ?, external_review_deadline = ?, internal_review_deadline = ?, recache_marks = ? WHERE property_id = ?");
         $result->bind_param('siissssssii', $this->marking, $this->pass_mark, $this->distinction_mark, $this->display_correct_answer, $this->display_students_response, $this->display_question_mark, $this->display_feedback, $this->external_review_deadline, $this->internal_review_deadline, $this->recache_marks, $this->property_id);
     } elseif ($configObject->get('cfg_summative_mgmt') and $this->paper_type == '2' and !$userObject->has_role(array('Admin', 'SysAdmin'))) {
         $result = $this->db->prepare("UPDATE properties SET paper_title = ?, paper_prologue = ?, paper_postscript = ?, bgcolor = ?, fgcolor = ?, themecolor = ?, labelcolor = ?, fullscreen = ?, marking = ?, bidirectional = ?, pass_mark = ?, distinction_mark = ?, folder = ?, rubric = ?, calculator = ?, display_correct_answer = ?, display_students_response = ?, display_question_mark = ?, display_feedback = ?, hide_if_unanswered = ?, external_review_deadline = ?, internal_review_deadline = ?, sound_demo = ?, password = ?, recache_marks = ? WHERE property_id = ?");
         $result->bind_param('ssssssssssiississsssssssii', $this->paper_title, $this->paper_prologue, $this->paper_postscript, $this->bgcolor, $this->fgcolor, $this->themecolor, $this->labelcolor, $this->fullscreen, $this->marking, $this->bidirectional, $this->pass_mark, $this->distinction_mark, $this->folder, $this->rubric, $this->calculator, $this->display_correct_answer, $this->display_students_response, $this->display_question_mark, $this->display_feedback, $this->hide_if_unanswered, $this->external_review_deadline, $this->internal_review_deadline, $this->sound_demo, $this->password, $this->recache_marks, $this->property_id);
     } else {
         $result = $this->db->prepare("UPDATE properties SET paper_title = ?, paper_type = ?, start_date = ?, end_date = ?, timezone = ?, paper_prologue = ?, paper_postscript = ?, bgcolor = ?, fgcolor = ?, themecolor = ?, labelcolor = ?, fullscreen = ?, marking = ?, bidirectional = ?, pass_mark = ?, distinction_mark = ?, folder = ?, labs = ?, rubric = ?, calculator = ?, exam_duration = ?, display_correct_answer = ?, display_students_response = ?, display_question_mark = ?, display_feedback = ?, hide_if_unanswered = ?, calendar_year = ?, external_review_deadline = ?, internal_review_deadline = ?, sound_demo = ?, password = ?, recache_marks = ?, deleted = ? WHERE property_id = ?");
         $result->bind_param('ssssssssssssssiisssiissssssssssisi', $this->paper_title, $this->paper_type, $this->raw_start_date, $this->raw_end_date, $this->timezone, $this->paper_prologue, $this->paper_postscript, $this->bgcolor, $this->fgcolor, $this->themecolor, $this->labelcolor, $this->fullscreen, $this->marking, $this->bidirectional, $this->pass_mark, $this->distinction_mark, $this->folder, $this->labs, $this->rubric, $this->calculator, $this->exam_duration, $this->display_correct_answer, $this->display_students_response, $this->display_question_mark, $this->display_feedback, $this->hide_if_unanswered, $this->calendar_year, $this->external_review_deadline, $this->internal_review_deadline, $this->sound_demo, $this->password, $this->recache_marks, $this->deleted, $this->property_id);
     }
     $result->execute();
     $result->close();
     // Record any changes
     $logger = new Logger($this->db);
     foreach ($this->changes as $change) {
         $logger->track_change('Paper', $this->property_id, $userObject->get_user_ID(), $change['old'], $change['new'], $change['part']);
     }
 }
Пример #9
0
 function Save($params, &$data)
 {
     global $string;
     echo "<h4>{$string['params']}</h4>";
     print_p($params);
     echo "<h4>{$string['generaldebuginfo']}</h4>";
     global $REPLACEMEuserIDold;
     $userObj = UserObject::get_instance();
     $userID = $userObj->get_user_ID();
     $data->ownerID = $userID;
     $this->data =& $data;
     $this->params =& $params;
     $this->ll = array();
     for ($i = 1; $i < 27; $i++) {
         $varletter = chr(ord('A') + $i - 1);
         $this->ll[$i] = $varletter;
     }
     // paper mode
     if (count($data->papers) > 0) {
         foreach ($data->papers as &$paper) {
             //print_p($paper);
             $this->output = $this->DoHeader();
             $this->output .= "\t<assessment title='" . $paper->paper_title . "' ident='" . $paper->load_id . "'>\n";
             if ($paper->rubric) {
                 $this->output .= "\t\t<rubric><![CDATA[" . $paper->rubric . "]]></rubric>\n";
             }
             foreach ($paper->screens as $id => &$screen) {
                 $this->output .= "\t\t<section title='Screen {$id}' ident='{$id}'>\n";
                 foreach ($screen->question_ids as $q_id) {
                     $question = FindQuestion($data->questions, $q_id);
                     if ($question) {
                         $this->OutputQuestion($question);
                     } else {
                         $this->AddError("Screen {$id} references questions {$q_id} which doesnt exist");
                     }
                 }
                 $this->output .= "\t\t</section>\n";
             }
             $this->output .= "\t</assessment>\n";
             $this->output .= sprintf("</questestinterop>\n");
             $filename = $params->base_dir . $params->dir . "/paper-" . $paper->load_id . ".xml";
             file_put_contents($filename, $this->output);
             //$data->files[$paper->paper_title] = $filename;
             $data->files[] = new ST_File("paper-" . $paper->load_id . ".xml", $paper->paper_title, $params->dir);
         }
     } else {
         // question mode
         $this->output = $this->DoHeader();
         // this needs a lot more work on this function
         foreach ($data->questions as $question) {
             $this->OutputQuestion($question);
         }
         $this->output .= sprintf("</questestinterop>\n");
         $filename = $params->base_dir . $params->dir . "/questions.xml";
         file_put_contents($filename, $this->output);
         $data->files[] = new ST_File("questions.xml", "Questions", $params->dir);
     }
     echo "<h4>QTI Output</h4>";
     echo "<pre>";
     echo htmlentities($this->output);
     echo "</pre>";
 }
Пример #10
0
 /**
  * Clear a user (student) from all modules for that session and attempt.
  *
  * @param integer $tmp_userID UserID of the member of student to remove
  * @param integer $session session year to be removed from
  * @param integer $attemp attempt to be removed from
  * @param object $db mysqli database connection
  *
  */
 static function clear_student_modules_by_userID($tmp_userID, $session, $attempt, $db)
 {
     $userObject = UserObject::get_instance();
     $result = $db->prepare("DELETE FROM modules_student WHERE userID = ? AND calendar_year = ? AND attempt = ?");
     $result->bind_param('isi', $tmp_userID, $session, $attempt);
     $result->execute();
     $result->close();
     if ($userObject->get_user_ID() == $tmp_userID) {
         $userObject->load_student_modules();
         // Re-cache modules if the user is the currently logged in person.
     }
 }
Пример #11
0
 /**
  * This function will output a message to the user and exit php; 
  *
  * @param string $title       - string title to display
  * @param string $msg         - string the message displayed on screen
  * @param string $reason      - string the message displayed in the database
  * @param string $icon        - name of the icon image file
  * @param string $title_color - color of the tile text
  * @param bool $output_header - if true output opening HTML tags
  * @param bool $output_footer - if true output closing HTML tags
  *
  */
 public function display_notice_and_exit($mysqli, $title, $msg, $reason, $icon, $title_color = 'black', $output_header = true, $output_footer = true)
 {
     $userObj = UserObject::get_instance();
     if (!is_null($mysqli)) {
         if ($userObj !== null and $userObj->get_user_ID() > 0) {
             $logger = new Logger($mysqli);
             $logger->record_access_denied($userObj->get_user_ID(), $title, $reason);
             // Record attempt in access denied log against userID.
         } else {
             $logger = new Logger($mysqli);
             $logger->record_access_denied(0, $title, $reason);
             // Record attempt in access denied log, userID set to zero.
         }
     }
     $this->display_notice($title, $msg, $icon, $title_color, $output_header, $output_footer);
     exit;
 }
Пример #12
0
 private function load_stats($type)
 {
     $this->stats = array();
     // Un-assigned papers should be limited to the owner.
     if ($this->idMod == 0) {
         $userObject = UserObject::get_instance();
         $ownerSQL = 'questions_modules.idMOD IS NULL AND ownerID = ' . $userObject->get_user_ID();
     } else {
         $ownerSQL = 'questions_modules.idMod =  ' . $this->idMod;
     }
     switch ($type) {
         case 'all':
         case 'type':
             $sql = 'SELECT COUNT(questions.q_id), q_type' . ' FROM questions LEFT JOIN questions_modules' . ' ON questions.q_id = questions_modules.q_id' . ' WHERE ' . $ownerSQL . ' AND deleted IS NULL AND status != -1 GROUP BY q_type';
             break;
         case 'status':
             $sql = 'SELECT COUNT(questions.q_id), name' . ' FROM (questions, question_statuses) LEFT JOIN questions_modules' . ' ON questions.q_id = questions_modules.q_id' . ' WHERE questions.status = question_statuses.id' . ' AND ' . $ownerSQL . ' AND deleted IS NULL GROUP BY status';
             break;
         case 'bloom':
             $sql = 'SELECT COUNT(questions.q_id), bloom' . ' FROM questions LEFT JOIN questions_modules' . ' ON questions.q_id = questions_modules.q_id' . ' WHERE ' . $ownerSQL . ' AND deleted IS NULL AND status != -1 GROUP BY bloom';
             break;
         case 'keyword':
             $sql = 'SELECT COUNT(questions.q_id), keywordID' . ' FROM (questions, keywords_question, keywords_user) LEFT JOIN questions_modules' . ' ON questions.q_id = questions_modules.q_id' . ' WHERE keywords_question.keywordID = keywords_user.id' . ' AND ' . $ownerSQL . ' AND questions.q_id = keywords_question.q_id' . ' AND deleted IS NULL AND status != -1 GROUP BY keywordID';
             break;
         case 'objective':
             $vle_api_data = MappingUtils::get_vle_api($this->idMod, date_utils::get_current_academic_year(), $vle_api_cache, $this->db);
             $all_years = getYearsForModules($vle_api_data['api'], array($this->idMod => $this->module_id), $this->db);
             $all_years = implode("','", $all_years);
             $sql = "SELECT COUNT(questions.q_id), relationships.obj_id" . " FROM (questions, relationships) LEFT JOIN questions_modules" . " ON questions.q_id = questions_modules.q_id" . " WHERE questions.q_id = relationships.question_id" . " AND {$ownerSQL} " . " AND calendar_year IN ('{$all_years}')" . " AND deleted IS NULL AND status != -1 GROUP BY relationships.obj_id";
             break;
     }
     $result = $this->db->prepare($sql);
     $result->execute();
     $result->bind_result($number, $type);
     while ($result->fetch()) {
         $this->stats[$type] = $number;
     }
     $result->close();
 }
Пример #13
0
 function Save($params, &$data)
 {
     global $mysqli, $string;
     echo "<h4>{$string['params']}</h4>";
     print_p($params);
     echo "<h4>{$string['othherdebug']}</h4>";
     $this->db = new Database();
     if (count($data->questions) == 0) {
         $this->AddError($string['noquestions']);
         return;
     }
     $paperid = $params->paper;
     $userObj = UserObject::get_instance();
     $userID = $userObj->get_user_ID();
     $db = new Database();
     $db->SetTable('properties');
     $db->AddField('*');
     $db->AddWhere('property_id', $paperid, 'i');
     $paper_row = $db->GetSingleRow();
     $ownerid = $userID;
     $data->ownerID = $userID;
     $nextscreen = 1;
     $nextid = 1;
     if ($paperid) {
         echo "{$string['addingtopaper']} {$paperid}<br>";
         $this->db->SetTable('papers');
         $this->db->AddField("max(screen) as screen");
         $this->db->AddField("max(display_pos) as display_pos");
         $this->db->AddWhere('paper', $paperid, 'i');
         $curpos = $this->db->GetSingleRow();
         $nextscreen = $curpos['screen'] + 1;
         $nextid = $curpos['display_pos'] + 1;
     }
     /*    // Get the actual ID of the module
             $this->db->SetTable('modules');
             $this->db->AddField('id');
             // Temp fix - if more than one team just get the first. Avoids error but doesn't fix the problem completely
             if (strpos($q_group, ',') !== false) {
               $q_group = strstr($q_group, ',', true);
             }
             $this->db->AddWhere('moduleid', $q_group, 's');
             $module_row = $this->db->GetSingleRow();
         */
     $module_id = -1;
     $paperutils = Paper_utils::get_instance();
     $module_id1 = $paperutils->get_modules($paper_row['property_id'], $mysqli);
     if ($module_id1 !== false) {
         $module_id = $module_id1;
     }
     $modutils = module_utils::get_instance();
     $q_group = $modutils->get_moduleid_from_id($module_id, $mysqli);
     if ($module_id !== false) {
         // Get a list of the team and user's keywords
         $user_keywords = array();
         if (is_array($module_id)) {
             foreach (array_keys($module_id) as $mod_id) {
                 $user_keywordsl = $this->GetExistingKeywords($mod_id);
                 $user_keywords = array_merge($user_keywords, $user_keywordsl);
             }
         } else {
             $user_keywords = $this->GetExistingKeywords($module_id);
         }
     }
     foreach ($data->questions as &$question) {
         $this->q_row = $this->db->GetBlankTableRow("questions");
         $this->o_row = $this->db->GetBlankTableRow("options");
         $this->o_rows = array();
         // stuff from parameters
         $this->q_row['ownerID'] = $ownerid;
         // general stuff that needs to be done for every qtype
         $this->q_row['creation_date'] = date("Y-m-d H:i:s");
         $this->q_row['last_edited'] = date("Y-m-d H:i:s");
         $this->q_row['q_type'] = $question->type;
         $this->q_row['status'] = isset($this->statuses[$question->status]) ? $this->statuses[$question->status] : $this->default_status;
         $this->q_row['theme'] = $question->theme;
         $this->q_row['notes'] = $question->notes;
         $this->q_row['leadin'] = $question->leadin;
         $this->q_row['bloom'] = $question->bloom;
         $this->q_row['q_media'] = $question->media;
         $this->q_row['q_media_width'] = $question->media_width;
         $this->q_row['q_media_height'] = $question->media_height;
         $this->q_row['deleted'] = null;
         $this->q_row['locked'] = null;
         $this->q_row['std'] = null;
         $this->q_row['q_option_order'] = $question->q_option_order;
         if (isset($question->settings)) {
             $this->q_row['settings'] = $question->settings;
         }
         $oiii = print_r($question, true);
         $t = 8;
         if ($question->type == "blank") {
             $this->SaveBlank($question);
         } elseif ($question->type == "calculation") {
             $this->SaveCalculation($question);
             $this->q_row['q_type'] = 'enhancedcalc';
         } elseif ($question->type == "dichotomous") {
             $this->SaveDichotomous($question);
         } elseif ($question->type == "extmatch") {
             $this->SaveExtMatch($question);
         } elseif ($question->type == "flash") {
             $this->SaveFlash($question);
         } elseif ($question->type == "hotspot") {
             $this->SaveHotspot($question);
         } elseif ($question->type == "info") {
             $this->SaveInfo($question);
         } elseif ($question->type == "labelling") {
             $this->SaveLabelling($question);
         } elseif ($question->type == "likert") {
             $this->SaveLikert($question);
         } elseif ($question->type == "matrix") {
             $this->SaveMatrix($question);
         } elseif ($question->type == "mcq") {
             $this->SaveMcq($question);
         } elseif ($question->type == "true_false") {
             $this->SaveTrueFalse($question);
         } elseif ($question->type == "mrq") {
             $this->SaveMrq($question);
         } elseif ($question->type == "rank") {
             $this->SaveRank($question);
         } elseif ($question->type == "textbox") {
             $this->SaveTextbox($question);
         } else {
             $this->AddError("Question type " . $question->type . " not yet supported", $question->load_id);
             continue;
         }
         if (!in_array($this->q_row['q_option_order'], array('display order', 'alphabetic', 'random'))) {
             $this->q_row['q_option_order'] = 'display order';
             print "correcting q_option_order";
         }
         if (!empty($this->q_row['scenario']) && strcasecmp("<p>&nbsp;</p>", $this->q_row['scenario']) == 0) {
             $this->q_row['scenario'] = '';
         }
         // create plain version of scenario and leadin
         $this->q_row['scenario_plain'] = empty($this->q_row['scenario']) ? '' : trim(strip_tags($this->q_row['scenario']));
         $this->q_row['leadin_plain'] = empty($this->q_row['leadin']) ? '' : trim(strip_tags($this->q_row['leadin']));
         if (!empty($this->q_row['correct_fback']) && !empty($this->q_row['incorrect_fback']) && $this->q_row['correct_fback'] == $this->q_row['incorrect_fback']) {
             $this->q_row['incorrect_fback'] = '';
         }
         // if no o_row, create a blank one
         if (count($this->o_rows) == 0 and $question->type != "calculation") {
             $this->o_row['marks_correct'] = 1;
             $this->o_row['marks_incorrect'] = 0;
             $this->o_row['marks_partial'] = 0;
             $this->o_rows[] = $this->o_row;
         }
         // store question row
         $this->db->InsertRow("questions", "q_id", $this->q_row);
         $question->save_id = $this->q_row['q_id'];
         $this->qm_row = $this->db->GetBlankTableRow("questions_modules");
         $this->qm_row['q_id'] = $this->q_row['q_id'];
         if (is_array($module_id)) {
             foreach (array_keys($module_id) as $mod_id) {
                 $this->qm_row['idMod'] = $mod_id;
                 $this->db->InsertRow("questions_modules", "temp", $this->qm_row);
             }
         } else {
             $this->qm_row['idMod'] = $module_id;
             $this->db->InsertRow("questions_modules", "temp", $this->qm_row);
         }
         $new_keywords = array();
         if ($module_id != -1) {
             if (is_array($module_id)) {
                 $user_keywords2 = array();
                 foreach (array_keys($module_id) as $mod_id) {
                     $new_keywords1 = $this->SaveKeywords($this->q_row['q_id'], $question->keywords, $mod_id, $user_keywords, $user_keywords2);
                     $new_keywords = array_merge($new_keywords, $new_keywords1);
                 }
                 $user_keywords = array_merge($user_keywords, $user_keywords2);
             } else {
                 $new_keywords = $this->SaveKeywords($this->q_row['q_id'], $question->keywords, $module_id, $user_keywords);
             }
         }
         // store option rows
         foreach ($this->o_rows as &$o_row) {
             $o_row['o_id'] = $this->q_row['q_id'];
             if (!empty($o_row['feedback_right']) && $o_row['feedback_right'] == $o_row['feedback_wrong']) {
                 $o_row['feedback_wrong'] = "";
             }
             $this->db->InsertRow("options", "id_num", $o_row);
         }
         // store additional metadata
         if ($question->load_id != '') {
             $meta_row = array('id' => null, 'questionID' => $question->save_id, 'type' => 'QTI Ident', 'value' => $question->load_id);
         }
         $this->db->InsertRow("questions_metadata", "id", $meta_row);
         echo "<h4>{$string['questiontables']}</h4>";
         echo "<div>{$string['questionsrow']}</div>";
         print_p($this->q_row, false);
         echo "<div>{$string['optionsrows']}</div>";
         print_p($this->o_rows, false, 100);
         echo "<div>{$string['newkeywords']}</div>";
         print_p($new_keywords, false);
         $track = array();
         $track['type'] = $string['qtiimport'];
         $track['typeID'] = $this->q_row['q_id'];
         $track['editor'] = $userID;
         $track['new'] = "{$string['imported1_2']} " . $params->original_filename;
         $track['part'] = "all";
         $track['changed'] = date("Y-m-d H:i:s");
         $db->InsertRow("track_changes", "id", $track);
         // we have a paper, add this question onto the list of questions for the paper
         if ($paperid && empty($data->papers)) {
             $p_row = $this->db->GetBlankTableRow('papers');
             $p_row['paper'] = $paperid;
             $p_row['question'] = $question->save_id;
             $p_row['screen'] = $nextscreen;
             $p_row['display_pos'] = $nextid++;
             $this->db->InsertRow('papers', 'p_id', $p_row);
         }
     }
     $logger = new Logger($mysqli);
     if (!empty($data->papers)) {
         foreach ($data->papers as &$paper) {
             foreach ($paper->screens as &$screen) {
                 foreach ($screen->question_ids as $q_id) {
                     $p_row = $this->db->GetBlankTableRow('papers');
                     echo sprintf($string['addingquestiondetails'], $q_id, $nextid, $nextscreen) . '<br>';
                     $p_row['paper'] = $paperid;
                     $q = FindQuestion($data->questions, $q_id);
                     $p_row['question'] = $q->save_id;
                     $p_row['screen'] = $nextscreen;
                     $p_row['display_pos'] = $nextid++;
                     $this->db->InsertRow('papers', 'p_id', $p_row);
                     $logger->track_change('Paper', $paperid, $userID, '', $q_id, 'Add Question (from QTI)');
                 }
                 $nextscreen++;
             }
         }
     }
 }
Пример #14
0
 public function createAccount()
 {
     $userObject = UserObject::get_instance();
     if (!$userObject->has_role('SysAdmin')) {
         return 'AccessDenied';
     }
     if (!isset($_POST['data'])) {
         return 'No data';
     }
     $xml = new SimpleXMLElement($_POST['data']);
     $fields = array('username', 'password', 'firstnames', 'title', 'surname', 'email', 'course', 'gender', 'yearofstudy', 'roles');
     foreach ($fields as $field) {
         if (isset($xml->{$field}) and $xml->{$field} != '') {
             ${$field} = $xml->{$field};
         } else {
             return 'Missing data: ' . $field;
         }
     }
     if (isset($xml->studentid)) {
         $studentid = $xml->studentid;
     } else {
         $studentid = '';
     }
     if ($roles != 'Student' and $roles != 'Staff' and $roles != 'Staff,Admin' and $roles != 'Staff,SysAdmin') {
         return 'Incorrect value for roles: ' . $roles;
     }
     $success = UserUtils::create_user($username, $password, $title, $firstnames, $surname, $email, $course, $gender, $yearofstudy, $roles, $studentid, $this->db);
     if ($success === false) {
         return false;
     } else {
         return $success;
     }
 }