Esempio n. 1
0
function enhancedcalc_remark($paper_type, $paper_id, $q_id, $settings, $db, $mode = 'unmarked')
{
    $status = array(-13 => 0, -12 => 0, -11 => 0, -10 => 0, -9 => 0, -8 => 0, -7 => 0, -6 => 0, -5 => 0, -4 => 0, -3 => 0, -2 => 0, -1 => 0, 0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0);
    $configObject = Config::get_instance();
    $enhancedcalc = new EnhancedCalc($configObject);
    $data['settings'] = $settings;
    $data['q_id'] = $q_id;
    $enhancedcalc->load($data);
    $mode_sql = $mode == 'all' ? '' : ' AND mark IS NULL';
    $result = $db->prepare("SELECT log{$paper_type}.id, user_answer FROM log{$paper_type}, log_metadata WHERE log{$paper_type}.metadataID = log_metadata.id AND q_id = ? AND paperID = ? {$mode_sql}");
    $result->bind_param('ii', $q_id, $paper_id);
    $result->execute();
    $result->store_result();
    $result->bind_result($id, $user_answer);
    while ($result->fetch()) {
        $enhancedcalc->set_useranswer($user_answer);
        $returnarray = $enhancedcalc->calculate_user_mark();
        $status[$returnarray]++;
        if ($returnarray !== Q_MARKING_UNMARKED and $returnarray !== Q_MARKING_ERROR) {
            // Save the extra data back into the log record.
            $sql = "UPDATE log{$paper_type} set mark = ?, adjmark = ?, totalpos = ?, user_answer = ? WHERE id = ? LIMIT 1";
            $storemark = $db->prepare($sql);
            $new_useranswerstring = $enhancedcalc->useranswer_to_string();
            $totalpos = $enhancedcalc->calculate_question_mark();
            $storemark->bind_param('dddsi', $enhancedcalc->qmark, $enhancedcalc->qmark, $totalpos, $new_useranswerstring, $id);
            $storemark->execute();
        }
    }
    $result->close();
    return $status;
}
Esempio n. 2
0
 /**
  * This function will output a message to the user 
  *
  * @param string $title       - title to display
  * @param string $msg         - string the message
  * @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($title, $msg, $icon, $title_color = 'black', $output_header = true, $output_footer = true)
 {
     $configObject = Config::get_instance();
     $root = str_replace('/classes', '/', str_replace('\\', '/', dirname(__FILE__)));
     if (file_exists($root . 'config/config.inc.php')) {
         $rp = $configObject->get('cfg_root_path');
         $cs = $configObject->get('cfg_page_charset');
     } else {
         // If we have not installed there is no config.inc.php file.
         $rp = rtrim('/' . trim(str_replace($_SERVER['DOCUMENT_ROOT'], '', $root), '/'), '/');
         $cs = 'utf-8';
     }
     if ($output_header == true) {
         echo "<html>\n";
         echo "<head>\n<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\n";
         echo "<meta http-equiv=\"content-type\" content=\"text/html;charset={$cs}\" />\n";
         echo "<title>{$title}</title>\n";
         echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"{$rp}/css/body.css\" />\n";
         echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"{$rp}/css/notice.css\" />\n";
         echo "</head>\n<body>\n";
     }
     echo '<div class="notice">';
     echo "<div style=\"float:left; padding-left:10px;width:60px\"><img src=\"{$rp}" . $icon . "\" width=\"48\" height=\"48\" /></div>\n";
     echo "<div><h1 style=\"color:{$title_color}\">{$title}</h1>\n";
     echo "<hr style=\"width:300px\"/>\n<p>{$msg}</p></div>";
     echo '</div>';
     if ($output_footer == true) {
         echo "\n</body>\n</html>";
     }
 }
Esempio n. 3
0
function listtreemodules($mysqli, $moduleid, $block_id, $plk, $flat = false, $explode = false)
{
    $icons = array('formative', 'progress', 'summative', 'survey', 'osce', 'offline', 'peer_review');
    $configObject = Config::get_instance();
    $moduleidorig = $moduleid;
    $moduleid = module_utils::get_idMod($moduleid, $mysqli);
    $sql = "SELECT DISTINCT crypt_name, paper_type, paper_title, retired, idMod FROM properties, properties_modules WHERE idMod = ? and properties.property_id = properties_modules.property_id AND deleted IS NULL AND paper_type IN ('0','1','3','4') ORDER BY paper_type, paper_title";
    $results2 = $mysqli->prepare($sql);
    $results2->bind_param('i', $moduleid);
    $results2->execute();
    $results2->bind_result($crypt_name, $paper_type, $paper_title, $retired, $moduleID);
    $results2->store_result();
    if ($results2->num_rows() > 0) {
        $rt = $results2->num_rows();
        echo '<div>';
        while ($results2->fetch()) {
            if (strtolower($_SESSION['_lti_context']['resource_link_title']) == strtolower($paper_title)) {
                $checked = ' checked';
            } else {
                $checked = '';
            }
            $extra = "<input type=\"radio\" name=\"paperlinkID\" id=\"paperlinkID-{$plk}\" value=\"{$plk}\"{$checked}><label for=\"paperlinkID-{$plk}\">";
            $extra1 = "</label>";
            echo "<div style=\"padding-left:20px\">{$extra}<img src=\"../artwork/" . $icons[$paper_type] . "_16.gif\" width=\"16\" height=\"16\" alt=\"" . $paper_type . "\" />&nbsp;" . $paper_title . "{$extra1}</div>\n";
            $_SESSION['postlookup'][$plk] = array($crypt_name, $moduleid);
            $plk++;
        }
        echo '</div>';
        $block_id++;
    } else {
        // no papers
    }
    $results2->close();
    return array($block_id, $plk);
}
Esempio n. 4
0
 protected function __construct()
 {
     $conf = Config::get_instance()->load("database")->get('db');
     $dsn = $conf['driver'] . ":dbname=" . $conf['database'] . ";host=" . $conf['host'];
     $options = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ);
     $this->pdo = new PDO($dsn, $conf['user'], $conf['pass'], $options);
 }
Esempio n. 5
0
 static function GetSmsUtils()
 {
     $configObject = Config::get_instance();
     $cfg_sms_api = $configObject->get('cfg_sms_api');
     if (isset($cfg_sms_api) and $cfg_sms_api != '') {
         require_once $configObject->get('cfg_web_root') . "/plugins/SMS/" . $cfg_sms_api . ".class.php";
         return new $cfg_sms_api();
     }
     return false;
 }
Esempio n. 6
0
 static function toilet_break_by_id($breakID, $db)
 {
     $configObject = Config::get_instance();
     $date_format = $configObject->get('cfg_long_date_time');
     $result = $db->prepare("SELECT DATE_FORMAT(break_taken, '" . $date_format . "') FROM toilet_breaks WHERE id = ?");
     $result->bind_param('i', $breakID);
     $result->execute();
     $result->bind_result($break_taken);
     $result->fetch();
     $result->close();
     return $break_taken;
 }
Esempio n. 7
0
 public static function GetCMAPI($vleapi)
 {
     $configObject = Config::get_instance();
     $classname = 'CM_' . $vleapi;
     $classfile = 'CM_' . $vleapi . '.class.php';
     try {
         include_once $configObject->get('cfg_web_root') . '/plugins/CM/' . $classfile;
         $object = new $classname();
     } catch (Exception $ex) {
         throw new ClassNotFoundException(sprintf($lang_strings['noclasserror'], $classname));
     }
     return $object;
 }
 /**
  * Return an array of the mid-exam announcements for the current paper.
  *
  * @return array         - Array of announcments keyed on Q_ID.
  */
 public function get_announcements()
 {
     $configObject = Config::get_instance();
     $announcements = array();
     $result = $this->db->prepare("SELECT q_id, q_number, screen, msg, DATE_FORMAT(created,'" . $configObject->get('cfg_long_date_time') . "') AS created FROM exam_announcements WHERE paperID = ? ORDER BY q_number");
     $result->bind_param('i', $this->paperID);
     $result->execute();
     $result->bind_result($q_id, $q_number, $screen, $msg, $created);
     while ($result->fetch()) {
         $announcements[$q_id] = array('q_number' => $q_number, 'screen' => $screen, 'msg' => $msg, 'created' => $created);
     }
     $result->close();
     return $announcements;
 }
Esempio n. 9
0
function display_q($configObject, $target_id, $db)
{
    $question_data = $db->prepare("SELECT q_type, q_id, score_method, display_method, settings, marks_correct, marks_incorrect, marks_partial, theme, scenario, leadin, correct, REPLACE(option_text,'\t','') AS option_text, q_media, q_media_width, q_media_height, o_media, o_media_width, o_media_height, notes FROM questions LEFT JOIN options ON questions.q_id = options.o_id WHERE q_id = ? ORDER BY id_num");
    $question_data->bind_param('i', $target_id);
    $question_data->execute();
    $question_data->store_result();
    $question_data->bind_result($q_type, $q_id, $score_method, $display_method, $settings, $marks_correct, $marks_incorrect, $marks_partial, $theme, $scenario, $leadin, $correct, $option_text, $q_media, $q_media_width, $q_media_height, $o_media, $o_media_width, $o_media_height, $notes);
    $num_rows = $question_data->num_rows;
    echo "<table cellpadding=\"4\" cellspacing=\"0\" border=\"0\" width=\"100%\" style=\"table-layout:fixed\">\n";
    echo "<col width=\"40\"><col>\n";
    $old_q_id = 0;
    while ($question_data->fetch()) {
        if ($old_q_id != $q_id) {
            $question['theme'] = trim($theme);
            $question['scenario'] = trim($scenario);
            $question['leadin'] = trim($leadin);
            $question['notes'] = trim($notes);
            $question['q_type'] = $q_type;
            $question['q_id'] = $q_id;
            $question['score_method'] = $score_method;
            $question['display_method'] = $display_method;
            $question['settings'] = $settings;
            $question['q_media'] = $q_media;
            $question['q_media_width'] = $q_media_width;
            $question['q_media_height'] = $q_media_height;
            $question['dismiss'] = '';
            $question['assigned_number'] = $_GET['qNo'];
        }
        $question['options'][] = array('correct' => $correct, 'option_text' => $option_text, 'o_media' => $o_media, 'o_media_width' => $o_media_width, 'o_media_height' => $o_media_height, 'marks_correct' => $marks_correct, 'marks_incorrect' => $marks_incorrect, 'marks_partial' => $marks_partial);
    }
    $question_data->close();
    $question_no = 0;
    $paper_type = 0;
    $unanswered = false;
    $question_offset = $_GET['qNo'];
    $screen_pre_submitted = 0;
    $user_answers = array();
    if ($question['q_type'] == 'enhancedcalc') {
        require_once '../plugins/questions/enhancedcalc/enhancedcalc.class.php';
        if (!isset($configObj)) {
            $configObj = Config::get_instance();
        }
        $question['object'] = new EnhancedCalc($configObj);
        $question['object']->load($question);
    }
    display_question($configObject, $question, $paper_type, 0, 1, '', $question_no, $user_answers, $unanswered);
    $question_nos[] = $old_q_id;
    echo "</table>\n";
}
Esempio n. 10
0
 function store_data($sessionstoreobj)
 {
     global $string;
     $configObj = Config::get_instance();
     $cfg_web_root = $configObj->get('cfg_web_root');
     $this->savetodebug('session store of input data key is ROGO_language');
     if (isset($_REQUEST['ROGO_language'])) {
         $_SESSION['ROGO_language'] = $_REQUEST['ROGO_language'];
         $language = LangUtils::getLang($cfg_web_root);
         $lang_path = "{$cfg_web_root}lang/{$language}/" . str_replace($cfg_web_root, '', $_SERVER['SCRIPT_FILENAME']);
         if (file_exists($lang_path)) {
             require $lang_path;
         }
     }
     return $sessionstoreobj;
 }
Esempio n. 11
0
 static function loadlangfile($file, $str = null)
 {
     if (is_null($str)) {
         global $string;
     } else {
         $string = $str;
     }
     $configObj = Config::get_instance();
     $cfg_web_root = $configObj->get('cfg_web_root');
     $language = LangUtils::getLang($cfg_web_root);
     $lang_path = "{$cfg_web_root}lang/{$language}/" . $file;
     if (file_exists($lang_path)) {
         require $lang_path;
     }
     return $string;
 }
Esempio n. 12
0
 static function load()
 {
     // Load the appropriate LTI integration class (if new one found load that else use this)
     $configObject = Config::get_instance();
     if (!is_null($configObject->get('lti_integration')) and $configObject->get('lti_integration') != '' and $configObject->get('lti_integration') != 'default') {
         $inc_file = $configObject->get('cfg_web_root') . 'plugins/LTI/' . $configObject->get('lti_integration') . '.class.php';
         if (file_exists($inc_file)) {
             require_once $inc_file;
         } else {
             echo "LTI Plugin not found: {$inc_file}";
             exit;
         }
         return new lti_integration_extended();
     } else {
         require_once $configObject->get('cfg_web_root') . '/plugins/LTI/' . 'default.class.php';
         return new lti_integration_extended();
     }
 }
Esempio n. 13
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;
     }
 }
Esempio n. 14
0
 /**
  * Get the IP address or name of the computer from the server headers
  * @return mixed client ip address
  */
 static function get_client_address()
 {
     $configObject = Config::get_instance();
     // If don't have cached version look it up
     if (!isset($_SESSION['current_ip'])) {
         if ($configObject->get('cfg_client_lookup') == 'name') {
             if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
                 $tmp_parts = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
                 $tmp_client_ipaddress = gethostbyaddr(trim($tmp_parts[0]));
             } else {
                 $tmp_client_ipaddress = gethostbyaddr($_SERVER['REMOTE_ADDR']);
             }
         } else {
             if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
                 $tmp_parts = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
                 $tmp_client_ipaddress = trim($tmp_parts[0]);
             } else {
                 $tmp_client_ipaddress = $_SERVER['REMOTE_ADDR'];
             }
         }
         $_SESSION['current_ip'] = $tmp_client_ipaddress;
     }
     return $_SESSION['current_ip'];
 }
Esempio n. 15
0
 public function db_user_change()
 {
     global $db_errors, $string;
     $configObject = Config::get_instance();
     $getback = array('cfg_db_sysadmin_user', 'cfg_db_sysadmin_passwd', 'cfg_db_admin_user', 'cfg_db_admin_passwd', 'cfg_db_staff_user', 'cfg_db_staff_passwd', 'cfg_db_student_user', 'cfg_db_student_passwd', 'cfg_db_external_user', 'cfg_db_external_passwd', 'cfg_db_inv_user', 'cfg_db_inv_passwd', 'cfg_db_database');
     $arr = $this->configObj->get($getback);
     foreach ($arr as $k => $v) {
         ${$k} = $v;
     }
     // Select the aproprate database user
     if ($this->has_role('SysAdmin')) {
         $result = $this->db->change_user($cfg_db_sysadmin_user, $cfg_db_sysadmin_passwd, $cfg_db_database);
     } elseif ($this->has_role(array('Staff', 'Admin'))) {
         // Process staff first to get higher priority than students
         $result = $this->db->change_user($cfg_db_staff_user, $cfg_db_staff_passwd, $cfg_db_database);
     } elseif ($this->has_role('Student')) {
         $result = $this->db->change_user($cfg_db_student_user, $cfg_db_student_passwd, $cfg_db_database);
     } elseif ($this->has_role('External Examiner')) {
         $result = $this->db->change_user($cfg_db_external_user, $cfg_db_external_passwd, $cfg_db_database);
     } elseif ($this->has_role('Invigilator')) {
         $result = $this->db->change_user($cfg_db_inv_user, $cfg_db_inv_passwd, $cfg_db_database);
     } else {
         $result = false;
         // new security routine
         $notice = UserNotices::get_instance();
         if (!is_array($this->roles) or isset($this->roles['']) and $this->roles[''] == 1) {
             $notice->access_denied($this->db, $string, '', true, true);
         } else {
             $notice->access_denied($this->db, $string, sprintf($string['denied_role'], implode(',', array_keys($this->roles))), true, true);
         }
     }
     if ($result == false) {
         $msg = 'This should never appear, please contact support';
         $support_email = $configObject->get('support_email');
         if ($support_email != '') {
             $msg .= " (<a href=\"{$support_email}\">{$support_email}</a>)";
         }
         $msg .= '.';
         $notice = UserNotices::get_instance();
         $notice->display_notice('Change DB user failed', $msg, '../artwork/exclamation_64.png', '#C00000', true, false);
         if ($this->db->error) {
             try {
                 throw new Exception("MySQL error " . $this->db->error . "<br /> ", $this->db->errno);
             } catch (Exception $e) {
                 echo "<p>Error No: " . $e->getCode() . " - " . $e->getMessage() . "</p>";
                 echo '<p>' . nl2br($e->getTraceAsString()) . '</p>';
                 echo "<body>\n</html>";
                 exit;
             }
         }
     }
 }
Esempio n. 16
0
 public function displayIcon($paper_type, $title, $initials, $surname, $locked, $retired)
 {
     $configObj = Config::get_instance();
     $paper_type = strval($paper_type);
     if ($retired != '') {
         $retired = '_retired';
     }
     if (isset($surname)) {
         $alt = "&#013;Author: {$title} {$initials} {$surname}";
     } else {
         $alt = '';
     }
     switch ($paper_type) {
         case '0':
             $html = "<img src=\"" . $configObj->get('cfg_root_path') . "/artwork/formative" . $retired . ".png\" alt=\"{$alt}\" />";
             break;
         case '1':
             $html = "<img src=\"" . $configObj->get('cfg_root_path') . "/artwork/progress" . $retired . ".png\" alt=\"{$alt}\" />";
             break;
         case '2':
             $html = "<img src=\"" . $configObj->get('cfg_root_path') . "/artwork/summative" . $retired . $locked . ".png\" alt=\"{$alt}\" />";
             break;
         case '3':
             $html = "<img src=\"" . $configObj->get('cfg_root_path') . "/artwork/survey" . $retired . ".png\" alt=\"{$alt}\" />";
             break;
         case '4':
             $html = "<img src=\"" . $configObj->get('cfg_root_path') . "/artwork/osce" . $retired . ".png\" alt=\"{$alt}\" />";
             break;
         case '5':
             $html = "<img src=\"" . $configObj->get('cfg_root_path') . "/artwork/offline" . $retired . ".png\" alt=\"{$alt}\" />";
             break;
         case '6':
             $html = "<img src=\"" . $configObj->get('cfg_root_path') . "/artwork/peer_review" . $retired . ".png\" alt=\"{$alt}\" />";
             break;
         case 'objectives':
             $html = "<img src=\"" . $configObj->get('cfg_root_path') . "/artwork/feedback_release_icon.png\" alt=\"Objectives Feedback\" />";
             break;
         case 'questions':
             $html = "<img src=\"" . $configObj->get('cfg_root_path') . "/artwork/question_release_icon.png\" alt=\"Questions Feedback\" />";
             break;
     }
     return $html;
 }
Esempio n. 17
0
function get_feedback_release_dates($date_range, $moduleIDs, &$papers, $db)
{
    $configObject = Config::get_instance();
    switch ($_GET['type']) {
        case 1:
            $report_type = 'objectives';
            break;
        case 2:
            $report_type = 'questions';
            break;
        case 3:
            $report_type = 'cohort_performance';
            break;
    }
    $sql = "SELECT feedback_release.paper_id, idfeedback_release, type, DATE_FORMAT(date, '" . $configObject->get('cfg_long_date_time') . "') FROM properties, properties_modules, feedback_release WHERE feedback_release.paper_id = properties.property_id AND properties.property_id = properties_modules.property_id {$date_range} AND paper_type = '2' AND feedback_release.type='{$report_type}' AND idMod IN (" . implode(',', $moduleIDs) . ") AND deleted IS NULL";
    $result = $db->prepare($sql);
    $result->execute();
    $result->bind_result($paperID, $idfeedback_release, $type, $date);
    while ($result->fetch()) {
        $papers[$paperID]['feedback_date'] = $date;
    }
    $result->close();
}
Esempio n. 18
0
 function update_password($postauthsuccessobj = '')
 {
     $configObj = Config::get_instance();
     $this->savetodebug('Called update_password');
     if ($this->updatable === true and (!isset($this->settings['donotupdatepassword']) or isset($this->settings['donotupdatepassword']) and $this->settings['donotupdatepassword'] !== true)) {
         if ($configObj->get('cfg_password_expire') == null) {
             $days = 30;
             // If there is no setting in the config file, default to 30 days.
         } else {
             $days = $configObj->get('cfg_password_expire');
         }
         $expire = time() + $days * 24 * 60 * 60;
         $this->savetodebug('Updating Password');
         extract($this->settings);
         $encpw_details = encpw($this->settings['encrypt_salt'], $this->form['std']->username, $this->form['std']->password);
         $stmt = $this->db->prepare("UPDATE {$table} SET {$passwd_col} = ?, password_expire = ? WHERE {$username_col} = ?");
         $stmt->bind_param('sis', $encpw_details, $expire, $this->form['std']->username);
         $stmt->execute();
         $stmt->close();
     } elseif (isset($this->settings['donotupdatepassword']) and $this->settings['donotupdatepassword'] === true) {
         $this->savetodebug('Not updating password due to settings flag');
     }
     return $postauthsuccessobj;
 }
Esempio n. 19
0
 static function get_past_papers($externalID, $db)
 {
     $config = Config::get_instance();
     $released_papers = array();
     $result = $db->prepare("SELECT properties.property_id, paper_title, crypt_name, DATE_FORMAT(start_date, '" . $config->get('cfg_long_date_time') . "') FROM properties, properties_reviewers, feedback_release WHERE properties.property_id = properties_reviewers.paperID AND end_date < NOW() AND properties_reviewers.paperID = feedback_release.paper_id AND feedback_release.type = 'external_examiner' AND properties_reviewers.reviewerID = ? AND properties_reviewers.type = 'external' ORDER BY end_date DESC");
     $result->bind_param('i', $externalID);
     $result->execute();
     $result->store_result();
     $result->bind_result($paperID, $paper_title, $crypt_name, $start_date);
     while ($result->fetch()) {
         $released_papers[$paperID] = array('paper_title' => $paper_title, 'crypt_name' => $crypt_name, 'start_date' => $start_date);
     }
     $result->close();
     return $released_papers;
 }
Esempio n. 20
0
 function is_email_in_cfg_institutional_domains($email)
 {
     $cfg = Config::get_instance();
     $domains = $cfg->get('cfg_institutional_domains');
     foreach ($domains as $d) {
         if (stripos($email, $d)) {
             return true;
         }
     }
     return false;
 }
Esempio n. 21
0
 public static function get_vle_api_data($vle_apis)
 {
     // Set up mapping APIs
     $configObject = Config::get_instance();
     if (is_array($vle_apis)) {
         foreach (array_keys($vle_apis) as $vle_api_id) {
             $classname = 'CM_' . $vle_api_id;
             require_once $configObject->get('cfg_web_root') . "/plugins/CM/{$classname}.class.php";
             $api = new $classname();
             $vle_apis[$vle_api_id]['name'] = $api->getFriendlyName(false, true);
             $vle_apis[$vle_api_id]['levels'] = $api->getMappingLevels();
         }
     }
     return $vle_apis;
 }
Esempio n. 22
0
     $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();
         $addKeyword->close();
     }
     $keyword_result->close();
 }
 // Look for and fix links in linked enhancedcalc questions
 if ($q_type == 'enhancedcalc') {
     require_once '../plugins/questions/enhancedcalc/enhancedcalc.class.php';
     if (!isset($configObj)) {
         $configObj = Config::get_instance();
     }
     $tmp_questions_array['theme'] = trim($theme);
     $tmp_questions_array['scenario'] = trim($scenario);
     $tmp_questions_array['leadin'] = trim($leadin);
     $tmp_questions_array['notes'] = trim($notes);
     $tmp_questions_array['q_type'] = $q_type;
     $tmp_questions_array['q_id'] = $question_id;
     //the newly inserted question ID!
     $tmp_questions_array['score_method'] = $score_method;
     $tmp_questions_array['status'] = $status;
     $tmp_questions_array['display_method'] = $display_method;
     $tmp_questions_array['settings'] = $settings;
     $tmp_questions_array['q_media'] = $q_media;
     $tmp_questions_array['q_media_width'] = $q_media_width;
     $tmp_questions_array['q_media_height'] = $q_media_height;
Esempio n. 23
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']);
     }
 }
Esempio n. 24
0
 function addImage($image, $width = '', $height = '', $imgnam = '')
 {
     global $import_directory;
     global $q_warnings;
     global $q_errors;
     global $file;
     global $wct;
     global $load_params;
     $configObject = Config::get_instance();
     $cfg_web_root = $configObject->get('cfg_web_root');
     if (stripos(" " . $image, "notes_icon.gif") > 0) {
         return;
     }
     echo "Adding image {$image}<br>";
     // download any http images etc here and put location in $imagefile as a LOCAL file
     $basename = basename($image);
     $imagefile = FindFile($import_directory, $basename);
     echo "Converted \"{$image}\" to base name \"{$imagefile}\"<br>";
     if ($imagefile == "" and $wct == 1) {
         list($discard, $split) = explode('=', $image);
         $pathinfo = pathinfo((string) $load_params->sourcefile);
         $imagefile = FindFileSub2($pathinfo['dirname'], '', '*' . $split . '*.' . pathinfo($imgnam, PATHINFO_EXTENSION));
         $imagefile = $pathinfo['dirname'] . '/' . $imagefile;
     } else {
         $imagefile = $import_directory . $imagefile;
     }
     if (strlen($imagefile) > strlen($import_directory) and file_exists($imagefile)) {
         $identifier_size = GetImageSize($imagefile);
         $this->media_width = $identifier_size[0];
         $this->media_height = $identifier_size[1];
         // if size different, then resize the image
         if ($width > 0 && $height > 0 && ($width != $this->media_width || $height != $this->media_height)) {
             $image = new SimpleImage();
             $image->load($imagefile);
             $image->resize($width, $height);
             $image->save($imagefile);
             echo "Resized {$imagefile} to {$width} x {$height}<br>";
             $this->x_scale = $width / $this->media_width;
             $this->y_scale = $height / $this->media_height;
             $this->media_width = $width;
             $this->media_height = $height;
         }
         $basename = basename($imagefile);
         $uniqueFilename = unique_filename($basename);
         copy($imagefile, $cfg_web_root . 'media/' . $uniqueFilename);
         echo "Copied {$imagefile} to " . $cfg_web_root . "media/{$uniqueFilename}<br />";
         $this->media = $uniqueFilename;
     } else {
         $this->media = basename($imagefile);
         $q_warnings[] = "Missing image {$image}";
     }
 }
Esempio n. 25
0
 function GetMedia($filename)
 {
     $configObject = Config::get_instance();
     $cfg_web_root = $configObject->get('cfg_web_root');
     if (file_exists($cfg_web_root . 'media/' . $filename)) {
         copy($cfg_web_root . 'media/' . $filename, $this->params->base_dir . $this->params->dir . '/' . $filename);
     }
 }
Esempio n. 26
0
 function loginbutton($displaystdformobj)
 {
     global $string;
     $config = Config::get_instance();
     $this->savetodebug('Button Check');
     $labs_list = '';
     // detect if we should display login button
     $paper_match = false;
     $ip_match = false;
     $query = "SELECT labs FROM properties WHERE start_date < DATE_ADD(NOW(), interval 15 minute) AND end_date > NOW() AND paper_type IN ('1', '2') AND labs != ''";
     $results = $this->db->prepare($query);
     if ($this->db->error) {
         try {
             $e = $this->db->error;
             $en = $this->db->errno;
             throw new Exception("MySQL error {$e} <br /> Query:<br /> {$query}", $en);
         } catch (Exception $e) {
             echo "Error No: " . $e->getCode() . " - " . $e->getMessage() . "<br />";
             echo nl2br($e->getTraceAsString());
         }
     }
     $results->execute();
     $results->store_result();
     $results->bind_result($labs);
     while ($results->fetch()) {
         $paper_match = true;
         $query = "SELECT address FROM client_identifiers WHERE lab IN ({$labs})";
         $sub_results = $this->db->prepare($query);
         if ($this->db->error) {
             try {
                 $e = $this->db->error;
                 $en = $this->db->errno;
                 throw new Exception("MySQL error {$e} <br /> Query:<br /> {$query}", $en);
             } catch (Exception $e) {
                 echo "Error No: " . $e->getCode() . " - " . $e->getMessage() . "<br />";
                 echo nl2br($e->getTraceAsString());
             }
         }
         $sub_results->execute();
         $sub_results->store_result();
         $sub_results->bind_result($address);
         while ($sub_results->fetch()) {
             $labs_list = $labs_list . ' ' . $address;
             if (NetworkUtils::get_client_address() == $address) {
                 $ip_match = true;
             }
         }
         $sub_results->close();
     }
     $results->close();
     $this->savetodebug('Status paper_match:' . var_export($paper_match, true) . ' ip_match:' . var_export($ip_match, true) . ' ip address:' . var_export(NetworkUtils::get_client_address(), true) . ' <br /> ' . $labs . ' ' . $labs_list);
     if ($paper_match === true and $ip_match === true) {
         $this->savetodebug('Adding New Button');
         $newbutton = new displaystdformobjbutton();
         $newbutton->type = 'button';
         $newbutton->value = ' ' . $string['guestbutton'] . ' ';
         $newbutton->name = 'guestlogin';
         $newbutton->class = 'guestlogin';
         $displaystdformobj->buttons[] = $newbutton;
         $newscript = "\$('.guestlogin').click(function() {\n  window.location.href = '" . $config->get('cfg_root_path') . "/users/guest_account.php';\n});";
         $displaystdformobj->scripts[] = $newscript;
     }
     return $displaystdformobj;
 }
Esempio n. 27
0
 public function setUp()
 {
     $confobj = Config::get_instance();
     $this->target = \Enhance\Core::getCodeCoverageWrapper('enhancedcalc', array($confobj));
 }
Esempio n. 28
0
 protected function __construct()
 {
     $this->config =& Config::get_instance();
     $this->config->load('app');
     $this->navi = Navigation::get_instance();
 }
Esempio n. 29
0
 */
$count = 16000;
$cfg_web_root = '../';
require_once '../include/custom_error_handler.inc';
require_once '../classes/configobject.class.php';
require_once '../classes/usernotices.class.php';
require_once '../classes/userobject.class.php';
require_once '../classes/dbutils.class.php';
@apache_setenv('no-gzip', 1);
@ini_set('implicit_flush', 1);
error_reporting(E_ALL);
@ob_implicit_flush(1);
@apache_setenv('no-gzip', 1);
@ini_set('implicit_flush', 1);
set_time_limit(0);
$configObject = Config::get_instance();
$notice = null;
$mysqli = DBUtils::get_mysqli_link($configObject->get('cfg_db_host'), $configObject->get('cfg_db_staff_user'), $configObject->get('cfg_db_staff_passwd'), $configObject->get('cfg_db_database'), $configObject->get('cfg_db_charset'), $notice, 'mysqli', 6446);
error_reporting(E_ALL);
$db = $mysqli;
if ($mysqli->error) {
    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());
    }
}
function execute($save_answers, $db, $count, $commit_interval = 800)
{
    global $log_id, $mark, $totalpos, $saved_response, $screen_no, $tmp_duration, $dismiss, $option_order, $metadataID;
Esempio n. 30
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);
}