echo "<table class='grades boxwidthwide boxaligncenter generalbox' border='0' cellpadding='5' cellspacing='5'>";
        echo "<caption>Oops!</caption>";
        echo "<tfoot><tr>";
        echo "<td colspan='12'><a href='{$CFG->wwwroot}/'><font color='black'>Return to Main</font></a></td>";
        echo "</tr></tfoot>";
        echo "<tbody><tr class='odd'><td><b>Current Course does not has any Quizzes.</b></td></tr>";
        echo "</tbody></table>";
    }
    if (!empty($param->edit)) {
        print_form_end();
    }
} else {
    //quiz_format_grade($quiz, $grade)
    //quiz_get_user_grades($quiz, $userid=0)
    if (!empty($param->edit)) {
        print_form_start($url, "post");
    }
    //echo "<table class='grades boxwidthwide boxaligncenter generalbox' border='0' cellpadding='5' cellspacing='5' width='100%'>";
    //style='border-color:#DDDDDD;'
    $cnt = count_records('quiz', 'course', $course->id);
    if ($cnt) {
        $quizzes = get_records('quiz', 'course', $course->id);
        if (!empty($quizzes)) {
            foreach ($quizzes as $quiz) {
                $hasRecords = count_records('quiz_course_activation', 'courseid', $course->id, 'quizid', $quiz->id);
                echo "<table class='grades boxwidthwide boxaligncenter generalbox' border='0' cellpadding='5' cellspacing='5' width='1000px'>";
                if ($hasRecords > 0) {
                    echo "<caption>{$quiz->name}</caption>";
                    printGradeTableHead();
                    // 12 columns total
                    echo "<tfoot>";
function print_instruction_form($url, $opt, $label, $selects, $course, $instrid, $edittext = '', $editselect = '', $disabled = false)
{
    // Display Add Instruction Form
    print_box_start('boxwidthwide boxaligncenter generalbox questioncategories contextlevel');
    $options = array('courseid' => $course->id, 'add' => $opt, 'instrid' => $instrid);
    echo "<table border='0' cellpadding='5' cellspacing='5' width='650px'>";
    echo "<tr><td>";
    print_form_start($url, "post");
    echo "<table border='0' cellpadding='5' cellspacing='5' width='650px'>";
    echo "<tr><th colspan='2' align='left'>Add Instructions</th></tr>";
    echo "<tr>";
    echo "<td>Instruction Type:</td>";
    echo "<td>";
    choose_from_menu($selects, 'typeid', $editselect, 'choose', '', '0', false, $disabled);
    echo "</td>";
    echo "</tr>";
    echo "<tr>";
    echo "<td>Instruction Text:</td>";
    echo "<td>";
    //print_textfield ('addkeyword', '','',25);
    //print_textarea($usehtmleditor, $rows, $cols, $width, $height, $name);
    print_textarea(can_use_html_editor(), 15, 45, 371, 167, 'instr', $edittext);
    echo "</td>";
    echo "</tr>";
    echo "</table>";
    print_button($label . " Instructions", $options);
    print_form_end();
    print_single_button($url, array('courseid' => $course->id), "Cancel");
    echo "</td>";
    echo "</tr>";
    echo "</table>";
    print_box_end();
}
         echo "<td>{$entry->username}</td>";
         echo "<td>{$entry->status}</td>";
         echo "<td>{$entry->url}</td>";
         echo "<td>" . date("M-d-Y h:i:s A", $entry->starttime) . "<br/>" . date("U", $entry->starttime) . "</td>";
         echo "<td>" . date("M-d-Y h:i:s A", $entry->endtime) . "<br/>" . date("U", $entry->endtime) . "</td>";
         echo "<td>" . format_time($entry->endtime - $entry->starttime) . "</td>";
         //format_time(time_after - time_before)
         echo "</tr>";
     }
     echo "</table>";
     print_box_end();
 } else {
     print_box_start('boxwidthwide boxaligncenter generalbox questioncategories contextlevel');
     echo "<b>Create Exam Entry</b><br/><br/>";
     $options = array('courseid' => $course->id);
     print_form_start($url);
     echo "<table border='0' cellpadding='5' cellspacing='5'>";
     echo "<tr>";
     echo "<td>Course ID:</td>";
     echo "<td colspan='2'>";
     print_textfield('courseid', '', '', 25);
     echo "</td>";
     echo "</tr>";
     echo "<tr>";
     echo "<td>Quiz ID:</td>";
     echo "<td colspan='2'>";
     print_textfield('quizid', '', '', 25);
     echo "</td>";
     echo "</tr>";
     echo "<tr>";
     echo "<td>Username:</td>";
function displayMainContextPage($course)
{
    global $CFG;
    $url = "{$CFG->wwwroot}/question/context.php";
    // Set RecordSets
    $group_records = get_records('context_key_groups', 'courseid', $course->id);
    $key_records = get_records('quiz_context_keys', 'courseid', $course->id, "key_id ASC");
    $quizkey_count = count_records('quiz_context_keys', 'courseid', $course->id);
    $group_count = count_records('context_key_groups', 'courseid', $course->id);
    print_heading($strspecialcategories);
    // Setup Form Values
    $selects = array();
    //if ($group_records = $DB->get_recordset('context_key_groups', array('courseid'=>$course->id))) {
    foreach ($group_records as $record) {
        $selects[$record->id] = $record->name;
    }
    //$group_records->close();
    // Print the Main Context Keys Page
    echo "<table border='0' cellpadding='5' cellspacing='5' class='boxwidthwide boxaligncenter generalbox questioncategories contextlevel'>";
    echo "<tr><td>";
    // Display Add Context Group Form
    print_box_start('boxwidthwide boxaligncenter generalbox questioncategories contextlevel');
    echo "<b>Add a Context Key Group</b><br/><br/>";
    $options = array('courseid' => $course->id, 'edit' => 1);
    print_form_start($url);
    print_textfield('addgroup', '', '', 25);
    echo "<br/>";
    print_button('Add Group', $options);
    print_form_end();
    print_box_end();
    echo "</td>";
    echo "<td>";
    // Display Remove Context Group Form
    print_box_start('boxwidthwide boxaligncenter generalbox questioncategories contextlevel');
    echo "<b>Remove a Context Key Group</b><br/><br/>";
    $options = array('courseid' => $course->id, 'edit' => 2);
    print_form_start($url);
    echo "Select Context Group:<br/>";
    choose_from_menu($selects, 'gid');
    echo "<br/>";
    print_button('Remove Group', $options);
    print_form_end();
    print_box_end();
    echo "</td></tr>";
    echo "<tr><td>";
    print_box_start('boxwidthwide boxaligncenter generalbox questioncategories contextlevel');
    //echo "<b>Add a Context Keyword</b><br/><br/>";
    $options = array('courseid' => $course->id);
    print_form_start($url);
    echo "<table border='0' cellpadding='5' cellspacing='5'>";
    echo "<tr><th colspan='2' align='left'>Add a Keyword</th></tr>";
    echo "<tr>";
    echo "<td>Keyword Name:</td>";
    echo "<td>";
    print_textfield('addkeyword', '', '', 25);
    echo "</td>";
    echo "</tr>";
    echo "<tr>";
    echo "<td colspan='2' align='right'>";
    print_button('Add Keyword', $options);
    echo "</td>";
    echo "</tr>";
    echo "</table>";
    print_form_end();
    print_box_end();
    echo "</td>";
    echo "<td>";
    // KeyWord Scroll Table
    print_box_start('boxwidthwide boxaligncenter generalbox questioncategories contextlevel');
    echo "<table summary='' cellpadding='0' cellspacing='1' align='center' title='' width='400' border='0' bgcolor='black'>";
    echo "<tr><td>";
    echo "<table summary='' cellpadding='0' cellspacing='0' width='100%' align='center' border='0'>";
    echo "<tr bgcolor='#FAFAFA'><td colspan='5' align='center'><b>Available Keywords</b></td></tr>";
    echo "<tr bgcolor='silver'>";
    echo "<td width='10%'> </td>";
    echo "<td width='28%'>Order</td>";
    echo "<td width='48%'>Keyword Name</td>";
    echo "<td width='14%'> </td>";
    echo "</tr></table></td></tr>";
    echo "<tr><td>";
    echo "<div style='width:100%; overflow:auto;height:150px;background-color:#FAFAFA'>";
    echo "<table summary='' cellpadding='0' cellspacing='0' width='96%' bgcolor='#FAFAFA'>";
    if ($quizkey_count) {
        //$key_records = $DB->get_recordset('quiz_context_keys', array('courseid'=>$course->id), "key_id ASC");
        foreach ($key_records as $r) {
            echo "<tr>";
            echo "<td width='10%'></td>";
            echo "<td width='30%'>" . $r->key_id . "</td>";
            echo "<td width='50%'>" . $r->key_code . "</td>";
            echo "<td width='10%'><a href='{$url}?courseid={$course->id}&editkey={$r->id}'>edit</a></td>";
            echo "</tr>";
        }
        //$key_records->close();
    } else {
        echo "<tr><td colspan='4' width='100%'><font size='2'>Currently, there are no available keywords.</font></td></tr>";
    }
    echo "</table></div>";
    echo "</td></tr></table>";
    print_box_end();
    echo "</td></tr>";
    echo "<tr><td colspan='2'>";
    $options = array('courseid' => $course->id);
    print_box_start('boxwidthwide boxaligncenter generalbox questioncategories contextlevel');
    echo "<table border='0' cellpadding='5' cellspacing='5'>";
    echo "<tr><th align='left'>Context</th><th></th><th align='left'>Define Keywords</th></tr>";
    echo "<tr>";
    echo "<td valign='top'>";
    // Display the list of Context Groups
    echo "<ol>";
    $group_records = get_records('context_key_groups', 'courseid', $course->id);
    foreach ($group_records as $r) {
        echo "<li><a style='color:blue'; onclick='getContext(" . $r->id . "," . $group_count . ");'>" . $r->name . "</a></li>";
    }
    //$group_records->close();
    echo "</ol>";
    echo "</td>";
    echo "<td width='100px'>";
    echo "</td>";
    echo "<td>";
    echo "<div id='define_keywords' style='display: ;'>Select a Context to edit keywords.</div>";
    // Display the Define Keyword Forms
    $group_records = get_records('context_key_groups', 'courseid', $course->id);
    foreach ($group_records as $rec) {
        echo "<div id='define_keywords_" . $rec->id . "' style='display: none;'>";
        print_form_start($url);
        echo $rec->name . "<br/>";
        echo "<table border='0' cellpadding='5' cellspacing='5'>";
        echo "<tr><th align='left'>KeyWord</th><th align='left'>Definition</th></tr>";
        $key_records = get_records('quiz_context_keys', 'courseid', $course->id, "key_id ASC");
        foreach ($key_records as $r) {
            $record = get_record_select('context_key_words', "key_group = '{$rec->id}' AND key_id = '{$r->key_id}' AND courseid = '{$course->id}'");
            echo "<tr>";
            echo "<td>" . $r->key_code . "</td>";
            echo "<td>";
            print_textfield('keyword' . $r->key_id, $record->keyword, '', 25);
            echo "</td>";
            echo "</tr>";
        }
        //$key_records->close();
        echo "<tr><td colspan='2' align='right'>";
        echo "<div id='define_keys_" . $rec->id . "'><input type='hidden' value='" . $rec->id . "' name='contextgroupid' /></div>";
        echo "</td></tr>";
        echo "<tr><td align='right'><br/><input type='button' onclick='closeDefine(" . $rec->id . ");' value='Cancel'/>";
        echo "</td><td align='left'>";
        print_button('Define Keywords', $options);
        echo "</td></tr>";
        echo "</table>";
        print_form_end();
        echo "</div>";
    }
    //$group_records->close();
    echo "</td>";
    echo "</table>";
    // JavaScript Functions
    echo "<script type='text/javascript'>";
    echo "function getContext(id,total) {";
    echo "var div;";
    echo "var i=0;";
    $i = 0;
    echo "var mydivs = new Array();";
    $group_records = get_records('context_key_groups', 'courseid', $course->id);
    foreach ($group_records as $r) {
        echo "mydivs[" . $i . "] = " . $r->id . ";";
        $i++;
    }
    //$group_records->close();
    echo "var cur=document.getElementById('define_keywords_'+id);";
    echo "var spc=document.getElementById('define_keywords');";
    //echo "for(i=1;i<=total;i++){";
    echo "for (i=0;i<mydivs.length;i++){";
    echo "div=document.getElementById('define_keywords_'+mydivs[i]);";
    echo "div.style.display='none';";
    echo "}";
    echo "spc.style.display='none';";
    echo "cur.style.display='';";
    echo "}";
    echo "function closeDefine(id) {";
    echo "var div=document.getElementById('define_keywords_'+id);";
    echo "var spc=document.getElementById('define_keywords');";
    echo "div.style.display='none';";
    echo "spc.style.display='';";
    echo "}";
    echo "</script>";
    print_box_end();
    echo "</td></tr>";
    echo "<tr><td colspan='2'>";
    // Nothing
    echo "</td></tr>";
    echo "<tr><td colspan='2'>";
    // Nothing
    echo "</td></tr>";
    echo "</table>";
}
function print_instruction_form($url, $opt, $label, $selects, $course, $instrid, $edittext = '', $editselect = '', $editquizzes = '', $disabled = false)
{
    // Display Add Instruction Form
    print_box_start('boxwidthwide boxaligncenter generalbox questioncategories contextlevel');
    $options = array('courseid' => $course->id, 'add' => $opt, 'instrid' => $instrid);
    // Sets the List of Quizzes that don't already have instructions assigned.
    $quizzes = array();
    /*
       if(!$disabled){
           if ($rs = get_records_sql("SELECT * FROM mdl_quiz WHERE course = $course->id AND id NOT IN (SELECT quizid FROM mdl_instructions WHERE quizid IS NOT NULL)")){
               foreach ($rs as $record) {
                   $quizzes[$record->id] = $record->name;
                   //echo $record->name."<br/>";
               }
               //echo "TEST:$course->id -> $editquizzes";
           }
       }else{
    *
    */
    if ($rs = get_records('quiz', 'course', $course->id)) {
        foreach ($rs as $record) {
            $quizzes[$record->id] = $record->name;
        }
    }
    //}
    echo "<table border='0' cellpadding='5' cellspacing='5' width='650px'>";
    echo "<tr><td>";
    print_form_start($url, "post");
    echo "<table border='0' cellpadding='5' cellspacing='5' width='650px'>";
    echo "<tr><th colspan='4' align='left'>Add Instructions</th></tr>";
    echo "<tr>";
    echo "<td>Instruction Type:</td>";
    echo "<td>";
    choose_from_menu($selects, 'typeid', $editselect, 'choose', '', '0', false, $disabled);
    echo "</td>";
    echo "</tr>";
    echo "<tr>";
    echo "<td>Course Quiz:</td>";
    echo "<td>";
    choose_from_menu($quizzes, 'quizid', $editquizzes, 'choose', '', '0', false, false);
    echo "</td>";
    echo "</tr>";
    echo "<tr>";
    echo "<td>Instruction Text:</td>";
    echo "<td>";
    //print_textfield ('addkeyword', '','',25);
    //print_textarea($usehtmleditor, $rows, $cols, $width, $height, $name);
    print_textarea(true, 15, 45, 371, 167, 'instr', $edittext);
    echo "</td>";
    echo "</tr>";
    echo "</table>";
    print_button($label . " Instructions", $options);
    print_form_end();
    print_single_button($url, array('courseid' => $course->id), "Cancel");
    echo "</td>";
    echo "</tr>";
    echo "</table>";
    print_box_end();
}