Index: temp_moodle_dev/moodle/lib/weblib.php =================================================================== diff -u --- temp_moodle_dev/moodle/lib/weblib.php (revision 0) +++ temp_moodle_dev/moodle/lib/weblib.php (revision b5e67f63747b4bb7072b78923d250396e77140f2) @@ -0,0 +1,7070 @@ +libdir/filterlib.php"); + +require_once("$CFG->libdir/ajax/ajaxlib.php"); + +/// Constants + +/// Define text formatting types ... eventually we can add Wiki, BBcode etc + +/** + * Does all sorts of transformations and filtering + */ +define('FORMAT_MOODLE', '0'); // Does all sorts of transformations and filtering + +/** + * Plain HTML (with some tags stripped) + */ +define('FORMAT_HTML', '1'); // Plain HTML (with some tags stripped) + +/** + * Plain text (even tags are printed in full) + */ +define('FORMAT_PLAIN', '2'); // Plain text (even tags are printed in full) + +/** + * Wiki-formatted text + * Deprecated: left here just to note that '3' is not used (at the moment) + * and to catch any latent wiki-like text (which generates an error) + */ +define('FORMAT_WIKI', '3'); // Wiki-formatted text + +/** + * Markdown-formatted text http://daringfireball.net/projects/markdown/ + */ +define('FORMAT_MARKDOWN', '4'); // Markdown-formatted text http://daringfireball.net/projects/markdown/ + +/** + * TRUSTTEXT marker - if present in text, text cleaning should be bypassed + */ +define('TRUSTTEXT', '#####TRUSTTEXT#####'); + + +/** + * Javascript related defines + */ +define('REQUIREJS_BEFOREHEADER', 0); +define('REQUIREJS_INHEADER', 1); +define('REQUIREJS_AFTERHEADER', 2); + +/** + * Allowed tags - string of html tags that can be tested against for safe html tags + * @global string $ALLOWED_TAGS + */ +global $ALLOWED_TAGS; +$ALLOWED_TAGS = +'


'; + } + if (has_capability('mod/quiz:viewreports', $context) && + count($attempts = get_records_select('quiz_attempts', "quiz = '$quiz->id' AND userid = '$attempt->userid'", 'attempt ASC')) > 1) { + /// List of all this user's attempts for people who can see reports. + $urloptions = ''; + if ($showall) { + $urloptions .= '&showall=true'; + } else if ($page > 0) { + $urloptions .= '&page=' . $page; + } + $attemptlist = array(); + foreach ($attempts as $at) { + if ($at->id == $attempt->id) { + $attemptlist[] = '' . $at->attempt . ''; + } else { + $attemptlist[] = '' . $at->attempt . ''; + } + } + $rows[] = ''; + } + +/// Timing information. + $rows[] = ''; + if ($attempt->timefinish) { + $rows[] = ''; + $rows[] = ''; + } + if (!empty($overtime)) { + $rows[] = ''; + } + +/// Show scores (if the user is allowed to see scores at the moment). + $grade = quiz_rescale_grade($attempt->sumgrades, $quiz); + if ($options->scores) { + if ($quiz->grade and $quiz->sumgrades) { + if($overtime) { + $result->sumgrades = "0"; + $result->grade = "0.0"; + } + + /// Show raw marks only if they are different from the grade (like on the view page. + if ($quiz->grade != $quiz->sumgrades) { + $a = new stdClass; + $a->grade = round($attempt->sumgrades, $CFG->quiz_decimalpoints); + $a->maxgrade = $quiz->sumgrades; + $rows[] = ''; + } + + /// Now the scaled grade. + $a = new stdClass; + $a->grade = '' . $grade . ''; + $a->maxgrade = $quiz->grade; + $a->percent = '' . round(($attempt->sumgrades/$quiz->sumgrades)*100, 0) . ''; + $rows[] = ''; + } + } + +/// Feedback if there is any, and the user is allowed to see it now. + $feedback = quiz_feedback_for_grade($grade, $attempt->quiz); + if ($options->overallfeedback && $feedback) { + $rows[] = ''; + } + +/// Now output the summary table, if there are any rows to be shown. + if (!empty($rows)) { + echo '
' . $picture . '' . + fullname($student, true) . '
' . get_string('attempts', 'quiz') . + '' . implode(', ', $attemptlist) . '
' . get_string('startedon', 'quiz') . + '' . userdate($attempt->timestart) . '
' . get_string('completedon', 'quiz') . '' . + userdate($attempt->timefinish) . '
' . get_string('timetaken', 'quiz') . '' . + $timetaken . '
' . get_string('overdue', 'quiz') . '' . $overtime . '
' . get_string('marks', 'quiz') . '' . + get_string('outofshort', 'quiz', $a) . '
' . get_string('grade') . '' . + get_string('outofpercent', 'quiz', $a) . '
' . get_string('feedback', 'quiz') . + '' . $feedback . '
', "\n"; + echo implode("\n", $rows); + echo "\n
\n"; + } + +/// Print the navigation panel if required + $numpages = quiz_number_of_pages($attempt->layout); + if ($numpages > 1 and !$showall) { + print_paging_bar($numpages, $page, 1, 'review.php?attempt='.$attempt->id.'&'); + echo '

'; + print_string('showall', 'quiz'); + echo '
'; + } + +/// Print all the questions + $number = quiz_first_questionnumber($attempt->layout, $pagelist); + foreach ($pagequestions as $i) { + if (!isset($questions[$i])) { + print_simple_box_start('center', '90%'); + echo '' . $number . '
'; + notify(get_string('errormissingquestion', 'quiz', $i)); + print_simple_box_end(); + $number++; // Just guessing that the missing question would have lenght 1 + continue; + } + $options->validation = QUESTION_EVENTVALIDATE === $states[$i]->event; + $options->history = ($isteacher and !$attempt->preview) ? 'all' : 'graded'; + // Print the question + print_question($questions[$i], $states[$i], $number, $quiz, $options); + $number += $questions[$i]->length; + } + + // Print the navigation panel if required + if ($numpages > 1 and !$showall) { + print_paging_bar($numpages, $page, 1, 'review.php?attempt='.$attempt->id.'&'); + } + + // print javascript button to close the window, if necessary + if (!$isteacher) { + include('attempt_close_js.php'); + } + + if (empty($popup)) { + print_footer($course); + } +?> Index: temp_moodle_dev/moodle/mod/quiz/view.php =================================================================== diff -u --- temp_moodle_dev/moodle/mod/quiz/view.php (revision 0) +++ temp_moodle_dev/moodle/mod/quiz/view.php (revision b5e67f63747b4bb7072b78923d250396e77140f2) @@ -0,0 +1,487 @@ +libdir.'/blocklib.php'); + require_once($CFG->libdir.'/gradelib.php'); + require_once($CFG->dirroot.'/mod/quiz/locallib.php'); + require_once($CFG->dirroot.'/mod/quiz/pagelib.php'); + + $id = optional_param('id', 0, PARAM_INT); // Course Module ID, or + $q = optional_param('q', 0, PARAM_INT); // quiz ID + $edit = optional_param('edit', -1, PARAM_BOOL); + + if ($id) { + if (! $cm = get_coursemodule_from_id('quiz', $id)) { + error("There is no coursemodule with id $id"); + } + if (! $course = get_record("course", "id", $cm->course)) { + error("Course is misconfigured"); + } + if (! $quiz = get_record("quiz", "id", $cm->instance)) { + error("The quiz with id $cm->instance corresponding to this coursemodule $id is missing"); + } + } else { + if (! $quiz = get_record("quiz", "id", $q)) { + error("There is no quiz with id $q"); + } + if (! $course = get_record("course", "id", $quiz->course)) { + error("The course with id $quiz->course that the quiz with id $q belongs to is missing"); + } + if (! $cm = get_coursemodule_from_instance("quiz", $quiz->id, $course->id)) { + error("The course module for the quiz with id $q is missing"); + } + } + + // Check login and get context. + require_login($course->id, false, $cm); + $context = get_context_instance(CONTEXT_MODULE, $cm->id); + + // if no questions have been set up yet redirect to edit.php + if (!$quiz->questions and has_capability('mod/quiz:manage', $context)) { + redirect($CFG->wwwroot . '/mod/quiz/edit.php?cmid=' . $cm->id); + } + + add_to_log($course->id, "quiz", "view", "view.php?id=$cm->id", $quiz->id, $cm->id); + + // Initialize $PAGE, compute blocks + $PAGE = page_create_instance($quiz->id); + $pageblocks = blocks_setup($PAGE); + $blocks_preferred_width = bounded_number(180, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]), 210); + + // Print the page header + if ($edit != -1 and $PAGE->user_allowed_editing()) { + $USER->editing = $edit; + } + + //only check pop ups if the user is not a teacher, and popup is set + + $bodytags = (has_capability('mod/quiz:attempt', $context) && $quiz->popup)?'onload="popupchecker(\'' . get_string('popupblockerwarning', 'quiz') . '\');"':''; + $PAGE->print_header($course->shortname.': %fullname%','',$bodytags); + + echo ''; + + if(!empty($CFG->showblocksonmodpages) && (blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $PAGE->user_is_editing())) { + echo ''; + } + + echo '
'; + print_container_start(); + blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT); + print_container_end(); + echo ''; + print_container_start(); + + // Print the main part of the page + + // Print heading and tabs (if there is more than one). + $currenttab = 'info'; + include('tabs.php'); + + // Print quiz name + + print_heading(format_string($quiz->name)); + + if (has_capability('mod/quiz:view', $context)) { + + // Print quiz description + if (trim(strip_tags($quiz->intro))) { + $formatoptions->noclean = true; + print_box(format_text($quiz->intro, FORMAT_MOODLE, $formatoptions), 'generalbox', 'intro'); + } + + echo '
'; + + // Print information about number of attempts and grading method. + if ($quiz->attempts > 1) { + echo "

".get_string("attemptsallowed", "quiz").": $quiz->attempts

"; + } + if ($quiz->attempts != 1) { + echo "

".get_string("grademethod", "quiz").": ".quiz_get_grading_option_name($quiz->grademethod)."

"; + } + + // Print information about timings. + $timenow = time(); + $available = ($quiz->timeopen < $timenow and ($timenow < $quiz->timeclose or !$quiz->timeclose)); + if ($available) { + if ($quiz->timelimit) { + echo "

".get_string("quiztimelimit","quiz", format_time($quiz->timelimit * 60))."

"; + } + if ($quiz->timeopen) { + echo '

', get_string('quizopens', 'quiz'), ': ', userdate($quiz->timeopen), '

'; + } + if ($quiz->timeclose) { + echo '

', get_string('quizcloses', 'quiz'), ': ', userdate($quiz->timeclose), '

'; + } + } else if ($timenow < $quiz->timeopen) { + echo "

".get_string("quiznotavailable", "quiz", userdate($quiz->timeopen))."

"; + } else { + echo "

".get_string("quizclosed", "quiz", userdate($quiz->timeclose))."

"; + } + echo '
'; + } else { + $available = false; + } + + // Show number of attempts summary to those who can view reports. + if (has_capability('mod/quiz:viewreports', $context)) { + if ($strattemptnum = quiz_num_attempt_summary($quiz, $cm)) { + echo ''; + } + } + + // Guests can't do a quiz, so offer them a choice of logging in or going back. + if (isguestuser()) { + $loginurl = $CFG->wwwroot.'/login/index.php'; + if (!empty($CFG->loginhttps)) { + $loginurl = str_replace('http:','https:', $loginurl); + } + + notice_yesno('

' . get_string('guestsno', 'quiz') . "

\n\n

" . + get_string('liketologin') . '

', $loginurl, get_referer(false)); + finish_page($course); + } + + if (!(has_capability('mod/quiz:attempt', $context) || has_capability('mod/quiz:preview', $context))) { + print_box('

' . get_string('youneedtoenrol', 'quiz') . '

' . + print_continue($CFG->wwwroot . '/course/view.php?id=' . $course->id, true) . + '

', 'generalbox', 'notice'); + finish_page($course); + } + + // Get this user's attempts. + $attempts = quiz_get_user_attempts($quiz->id, $USER->id); + $unfinished = false; + if ($unfinishedattempt = quiz_get_user_attempt_unfinished($quiz->id, $USER->id)) { + $attempts[] = $unfinishedattempt; + $unfinished = true; + } + $numattempts = count($attempts); + + // Work out the final grade, checking whether it was overridden in the gradebook. + $mygrade = quiz_get_best_grade($quiz, $USER->id); + $mygradeoverridden = false; + $gradebookfeedback = ''; + + $grading_info = grade_get_grades($course->id, 'mod', 'quiz', $quiz->id, $USER->id); + if (!empty($grading_info->items)) { + $item = $grading_info->items[0]; + if (isset($item->grades[$USER->id])) { + $grade = $item->grades[$USER->id]; + + if ($grade->overridden) { + $mygrade = $grade->grade + 0; // Convert to number. + $mygradeoverridden = true; + } + if (!empty($grade->str_feedback)) { + $gradebookfeedback = $grade->str_feedback; + } + } + } + + // Print table with existing attempts + if ($attempts) { + + print_heading(get_string('summaryofattempts', 'quiz')); + + // Work out which columns we need, taking account what data is available in each attempt. + list($someoptions, $alloptions) = quiz_get_combined_reviewoptions($quiz, $attempts, $context); + + $gradecolumn = $someoptions->scores && $quiz->grade && $quiz->sumgrades; + $markcolumn = $gradecolumn && ($quiz->grade != $quiz->sumgrades); + $overallstats = $alloptions->scores; + + $feedbackcolumn = quiz_has_feedback($quiz->id); + $overallfeedback = $feedbackcolumn && $alloptions->overallfeedback; + + // Prepare table header + $table->class = 'generaltable quizattemptsummary'; + $table->head = array(get_string('attempt', 'quiz'), get_string('timecompleted', 'quiz')); + $table->align = array('center', 'left'); + $table->size = array('', ''); + if ($markcolumn) { + $table->head[] = get_string('marks', 'quiz') . " / $quiz->sumgrades"; + $table->align[] = 'center'; + $table->size[] = ''; + } + if ($gradecolumn) { + $table->head[] = get_string('grade') . " / $quiz->grade"; + $table->align[] = 'center'; + $table->size[] = ''; + } + if ($feedbackcolumn) { + $table->head[] = get_string('feedback', 'quiz'); + $table->align[] = 'left'; + $table->size[] = ''; + } + if (isset($quiz->showtimetaken)) { + $table->head[] = get_string('timetaken', 'quiz'); + $table->align[] = 'left'; + $table->size[] = ''; + } + + // One row for each attempt + foreach ($attempts as $attempt) { + $attemptoptions = quiz_get_reviewoptions($quiz, $attempt, $context); + $row = array(); + + // Add the attempt number, making it a link, if appropriate. + if ($attempt->preview) { + $row[] = make_review_link(get_string('preview', 'quiz'), $quiz, $attempt); + } else { + $row[] = make_review_link($attempt->attempt, $quiz, $attempt); + } + + // prepare strings for time taken and date completed + $timetaken = ''; + $datecompleted = ''; + if ($attempt->timefinish > 0) { + // attempt has finished + $timetaken = format_time($attempt->timefinish - $attempt->timestart); + $datecompleted = userdate($attempt->timefinish); + } else if ($available) { + // The attempt is still in progress. + $timetaken = format_time(time() - $attempt->timestart); + $datecompleted = ''; + } else if ($quiz->timeclose) { + // The attempt was not completed but is also not available any more becuase the quiz is closed. + $timetaken = format_time($quiz->timeclose - $attempt->timestart); + $datecompleted = userdate($quiz->timeclose); + } else { + // Something weird happened. + $timetaken = ''; + $datecompleted = ''; + } + $row[] = $datecompleted; + + if ($markcolumn && $attempt->timefinish > 0) { + if ($attemptoptions->scores) { + $row[] = make_review_link(round($attempt->sumgrades, $quiz->decimalpoints), $quiz, $attempt); + } else { + $row[] = ''; + } + } + + // Ouside the if because we may be showing feedback but not grades. + $attemptgrade = quiz_rescale_grade($attempt->sumgrades, $quiz); + + if ($gradecolumn) { + if ($attemptoptions->scores && $attempt->timefinish > 0) { + $formattedgrade = $attemptgrade; + // highlight the highest grade if appropriate + if ($overallstats && $numattempts > 1 && !is_null($mygrade) && $attemptgrade == $mygrade && $quiz->grademethod == QUIZ_GRADEHIGHEST) { + $table->rowclass[$attempt->attempt] = 'bestrow'; + } + + $row[] = make_review_link($formattedgrade, $quiz, $attempt); + } else { + $row[] = ''; + } + } + + if ($feedbackcolumn && $attempt->timefinish > 0) { + if ($attemptoptions->overallfeedback) { + $row[] = quiz_feedback_for_grade($attemptgrade, $quiz->id); + } else { + $row[] = ''; + } + } + + if (isset($quiz->showtimetaken)) { + $row[] = $timetaken; + } + + $table->data[$attempt->attempt] = $row; + } // End of loop over attempts. + print_table($table); + } + + // Print information about the student's best score for this quiz if possible. + $moreattempts = $unfinished || $numattempts < $quiz->attempts || $quiz->attempts == 0; + if (!$moreattempts) { + print_heading(get_string("nomoreattempts", "quiz")); + } + + if ($numattempts && $quiz->sumgrades && !is_null($mygrade)) { + $resultinfo = ''; + + if ($overallstats) { + if ($available && $moreattempts) { + $a = new stdClass; + $a->method = quiz_get_grading_option_name($quiz->grademethod); + $a->mygrade = $mygrade; + $a->quizgrade = $quiz->grade; + $resultinfo .= print_heading(get_string('gradesofar', 'quiz', $a), '', 2, 'main', true); + } else { + $resultinfo .= print_heading(get_string('yourfinalgradeis', 'quiz', "$mygrade / $quiz->grade"), '', 2, 'main', true); + if ($mygradeoverridden) { + $resultinfo .= '

'.get_string('overriddennotice', 'grades').'

'; + } + } + } + + if ($gradebookfeedback) { + $resultinfo .= print_heading(get_string('comment', 'quiz'), '', 3, 'main', true); + $resultinfo .= '

'.$gradebookfeedback.'

'; + } + if ($overallfeedback) { + $resultinfo .= print_heading(get_string('overallfeedback', 'quiz'), '', 3, 'main', true); + $resultinfo .= '

'.quiz_feedback_for_grade($mygrade, $quiz->id).'

'; + } + + if ($resultinfo) { + print_box($resultinfo, 'generalbox', 'feedback'); + } + } + + // Print a button to start/continue an attempt, if appropriate. + if (!$quiz->questions) { + print_heading(get_string("noquestions", "quiz")); + + } else if ($available && $moreattempts) { + echo "
"; + echo "
"; + + if ($unfinished) { + if (has_capability('mod/quiz:preview', $context)) { + $buttontext = get_string('continuepreview', 'quiz'); + } else { + $buttontext = get_string('continueattemptquiz', 'quiz'); + } + } else { + + // Work out the appropriate button caption. + if (has_capability('mod/quiz:preview', $context)) { + $buttontext = get_string('previewquiznow', 'quiz'); + } else if ($numattempts == 0) { + $buttontext = get_string('attemptquiznow', 'quiz'); + } else { + $buttontext = get_string('reattemptquiz', 'quiz'); + } + + // Work out if the quiz is temporarily unavailable because of the delay option. + if (!empty($attempts)) { + $tempunavailable = ''; + $lastattempt = end($attempts); + $lastattempttime = $lastattempt->timefinish; + if ($numattempts == 1 && $quiz->delay1 && $timenow <= $lastattempttime + $quiz->delay1) { + $tempunavailable = get_string('temporaryblocked', 'quiz') . + ' '. userdate($lastattempttime + $quiz->delay1). ''; + } else if ($numattempts > 1 && $quiz->delay2 && $timenow <= $lastattempttime + $quiz->delay2) { + $tempunavailable = get_string('temporaryblocked', 'quiz') . + ' '. userdate($lastattempttime + $quiz->delay2). ''; + } + + // If so, display a message and prevent the start button from appearing. + if ($tempunavailable) { + print_simple_box($tempunavailable, "center"); + print_continue($CFG->wwwroot . '/course/view.php?id=' . $course->id); + $buttontext = ''; + } + } + } + + // Actually print the start button. + if ($buttontext) { + $buttontext = htmlspecialchars($buttontext, ENT_QUOTES); + + // Do we need a confirm javascript alert? + if ($unfinished) { + $strconfirmstartattempt = ''; + } else if ($quiz->timelimit && $quiz->attempts) { + $strconfirmstartattempt = get_string('confirmstartattempttimelimit','quiz', $quiz->attempts); + } else if ($quiz->timelimit) { + $strconfirmstartattempt = get_string('confirmstarttimelimit','quiz'); + } else if ($quiz->attempts) { + $strconfirmstartattempt = get_string('confirmstartattemptlimit','quiz', $quiz->attempts); + } else { + $strconfirmstartattempt = ''; + } + // Determine the URL to use. + $attempturl = "attempt.php?id=$cm->id"; + + // Prepare options depending on whether the quiz should be a popup. + if (!empty($quiz->popup)) { + $window = 'quizpopup'; + $windowoptions = "left=0, top=0, height='+window.screen.height+', " . + "width='+window.screen.width+', channelmode=yes, fullscreen=yes, " . + "scrollbars=yes, resizeable=no, directories=no, toolbar=no, " . + "titlebar=no, location=no, status=no, menubar=no"; + if (!empty($CFG->usesid) && !isset($_COOKIE[session_name()])) { + $attempturl = sid_process_url($attempturl); + } + + echo ''; + } else { + print_single_button("attempt.php", array('id'=>$cm->id), $buttontext, 'get', '', false, '', false, $strconfirmstartattempt); + } + + +?> + +\n"; + } else { + print_continue($CFG->wwwroot . '/course/view.php?id=' . $course->id); + } + + // Should we not be seeing if we need to print right-hand-side blocks? + + finish_page($course); + +// Utility functions ================================================================= + +function finish_page($course) { + global $THEME; + print_container_end(); + echo '
'; + print_footer($course); + exit; +} + +/** Make some text into a link to review the quiz, if that is appropriate. */ +function make_review_link($linktext, $quiz, $attempt) { + // If not even responses are to be shown in review then we don't allow any review + if (!($quiz->review & QUIZ_REVIEW_RESPONSES)) { + return $linktext; + } + + // If the quiz is still open, are reviews allowed? + if ((!$quiz->timeclose or time() < $quiz->timeclose) and !($quiz->review & QUIZ_REVIEW_OPEN & QUIZ_REVIEW_RESPONSES)) { + // If not, don't link. + return $linktext; + } + + // If the quiz is closed, are reviews allowed? + if (($quiz->timeclose and time() > $quiz->timeclose) and !($quiz->review & QUIZ_REVIEW_CLOSED & QUIZ_REVIEW_RESPONSES)) { + // If not, don't link. + return $linktext; + } + + // If the attempt is still open, don't link. + if (!$attempt->timefinish) { + return $linktext; + } + + $url = "review.php?q=$quiz->id&attempt=$attempt->id"; + if ($quiz->popup) { + $windowoptions = "left=0, top=0, channelmode=yes, fullscreen=yes, scrollbars=yes, resizeable=no, directories=no, toolbar=no, titlebar=no, location=no, status=no, menubar=no"; + return link_to_popup_window('/mod/quiz/' . $url, 'quizpopup', $linktext, '+window.screen.height+', '+window.screen.width+', '', $windowoptions, true); + } else { + return "$linktext"; + } +} +?> Index: temp_moodle_dev/moodle/question/edit.php =================================================================== diff -u --- temp_moodle_dev/moodle/question/edit.php (revision 0) +++ temp_moodle_dev/moodle/question/edit.php (revision b5e67f63747b4bb7072b78923d250396e77140f2) @@ -0,0 +1,62 @@ +lowest(); + $streditingquestions = get_string('editquestions', "quiz"); + if ($cm!==null) { + $strupdatemodule = has_capability('moodle/course:manageactivities', $contexts->lowest()) + ? update_module_button($cm->id, $COURSE->id, get_string('modulename', $cm->modname)) + : ""; + $navlinks = array(); + $navlinks[] = array('name' => get_string('modulenameplural', $cm->modname), 'link' => "$CFG->wwwroot/mod/{$cm->modname}/index.php?id=$COURSE->id", 'type' => 'activity'); + $navlinks[] = array('name' => format_string($module->name), 'link' => "$CFG->wwwroot/mod/{$cm->modname}/view.php?id={$cm->id}", 'type' => 'title'); + $navlinks[] = array('name' => $streditingquestions, 'link' => '', 'type' => 'title'); + $navigation = build_navigation($navlinks); + print_header_simple($streditingquestions, '', $navigation, "", "", true, $strupdatemodule); + + $currenttab = 'edit'; + $mode = 'questions'; + ${$cm->modname} = $module; + include($CFG->dirroot."/mod/$cm->modname/tabs.php"); + } else { + // Print basic page layout. + $navlinks = array(); + $navlinks[] = array('name' => $streditingquestions, 'link' => '', 'type' => 'title'); + $navigation = build_navigation($navlinks); + + print_header_simple($streditingquestions, '', $navigation); + + // print tabs + $currenttab = 'questions'; + include('tabs.php'); + } + + + echo ''; + echo ''; + echo '
'; + + question_showbank('questions', $contexts, $thispageurl, $cm, $pagevars['qpage'], $pagevars['qperpage'], $pagevars['qsortorder'], $pagevars['qsortorderdecoded'], + $pagevars['cat'], $pagevars['recurse'], $pagevars['showhidden'], $pagevars['showquestiontext']); + + echo '
'; + + print_footer($COURSE); +?> Index: temp_moodle_dev/moodle/question/export.php =================================================================== diff -u --- temp_moodle_dev/moodle/question/export.php (revision 0) +++ temp_moodle_dev/moodle/question/export.php (revision b5e67f63747b4bb7072b78923d250396e77140f2) @@ -0,0 +1,145 @@ +id"); + list($catid, $catcontext) = explode(',', $pagevars['cat']); + if (!$category = get_record("question_categories", "id", $catid, 'contextid', $catcontext)) { + print_error('nocategory','quiz'); + } + + /// Header + if ($cm!==null) { + $strupdatemodule = has_capability('moodle/course:manageactivities', $contexts->lowest()) + ? update_module_button($cm->id, $COURSE->id, get_string('modulename', $cm->modname)) + : ""; + $navlinks = array(); + $navlinks[] = array('name' => get_string('modulenameplural', $cm->modname), 'link' => "$CFG->wwwroot/mod/{$cm->modname}/index.php?id=$COURSE->id", 'type' => 'activity'); + $navlinks[] = array('name' => format_string($module->name), 'link' => "$CFG->wwwroot/mod/{$cm->modname}/view.php?id={$cm->id}", 'type' => 'title'); + $navlinks[] = array('name' => $strexportquestions, 'link' => '', 'type' => 'title'); + $navigation = build_navigation($navlinks); + print_header_simple($strexportquestions, '', $navigation, "", "", true, $strupdatemodule); + + $currenttab = 'edit'; + $mode = 'export'; + ${$cm->modname} = $module; + include($CFG->dirroot."/mod/$cm->modname/tabs.php"); + } else { + // Print basic page layout. + $navlinks = array(); + $navlinks[] = array('name' => $strexportquestions, 'link' => '', 'type' => 'title'); + $navigation = build_navigation($navlinks); + + print_header_simple($strexportquestions, '', $navigation); + // print tabs + $currenttab = 'export'; + include('tabs.php'); + } + + $exportfilename = default_export_filename($COURSE, $category); + $export_form = new question_export_form($thispageurl, array('contexts'=>$contexts->having_one_edit_tab_cap('export'), 'defaultcategory'=>$pagevars['cat'], + 'defaultfilename'=>$exportfilename)); + + + if ($from_form = $export_form->get_data()) { /// Filename + + + if (! is_readable("format/$from_form->format/format.php")) { + error("Format not known ($from_form->format)"); + } + + // load parent class for import/export + require_once("format.php"); + + // and then the class for the selected format + require_once("format/$from_form->format/format.php"); + + $classname = "qformat_$from_form->format"; + $qformat = new $classname(); + $qformat->setContexts($contexts->having_one_edit_tab_cap('export')); + $qformat->setCategory($category); + $qformat->setCourse($COURSE); + + if (empty($from_form->exportfilename)) { + $from_form->exportfilename = default_export_filename($COURSE, $category); + } + $qformat->setFilename($from_form->exportfilename); + $canaccessbackupdata = has_capability('moodle/site:backup', $contexts->lowest()); + $qformat->set_can_access_backupdata($canaccessbackupdata); + $qformat->setCattofile(!empty($from_form->cattofile)); + $qformat->setContexttofile(!empty($from_form->contexttofile)); + + if (! $qformat->exportpreprocess()) { // Do anything before that we need to + print_error('exporterror', 'quiz', $thispageurl->out()); + } + + if (! $qformat->exportprocess()) { // Process the export data + print_error('exporterror', 'quiz', $thispageurl->out()); + } + + if (! $qformat->exportpostprocess()) { // In case anything needs to be done after + print_error('exporterror', 'quiz', $thispageurl->out()); + } + echo "
"; + + // link to download the finished file + $file_ext = $qformat->export_file_extension(); + $filename = $from_form->exportfilename . $file_ext; + if ($canaccessbackupdata) { + $efile = get_file_url($qformat->question_get_export_dir() . '/' . $filename, + array('forcedownload' => 1)); + echo '

'; + echo '

' . + get_string('downloadextra', 'quiz') . '

'; + } else { + $efile = get_file_url($filename, null, 'questionfile'); + echo '

' . + get_string('yourfileshoulddownload', 'question', $efile) . '

'; + echo ' +'; + } + + print_continue('edit.php?' . $thispageurl->get_query_string()); + print_footer($COURSE); + exit; + } + + /// Display export form + print_heading_with_help($strexportquestions, 'export', 'quiz'); + + $export_form->display(); + + print_footer($COURSE); +?> Index: temp_moodle_dev/moodle/question/import.php =================================================================== diff -u --- temp_moodle_dev/moodle/question/import.php (revision 0) +++ temp_moodle_dev/moodle/question/import.php (revision b5e67f63747b4bb7072b78923d250396e77140f2) @@ -0,0 +1,162 @@ +libdir . '/uploadlib.php'); + require_once($CFG->libdir . '/questionlib.php'); + require_once("import_form.php"); + + list($thispageurl, $contexts, $cmid, $cm, $module, $pagevars) = question_edit_setup('import', false, false); + + // get display strings + $txt = new stdClass(); + $txt->importquestions = get_string("importquestions", "quiz"); + + list($catid, $catcontext) = explode(',', $pagevars['cat']); + if (!$category = get_record("question_categories", "id", $catid)) { + print_error('nocategory','quiz'); + } + + //this page can be called without courseid or cmid in which case + //we get the context from the category object. + if ($contexts === null) { // need to get the course from the chosen category + $contexts = new question_edit_contexts(get_context_instance_by_id($category->contextid)); + $thiscontext = $contexts->lowest(); + if ($thiscontext->contextlevel == CONTEXT_COURSE){ + require_login($thiscontext->instanceid, false); + } elseif ($thiscontext->contextlevel == CONTEXT_MODULE){ + list($module, $cm) = get_module_from_cmid($thiscontext->instanceid); + require_login($cm->course, false, $cm); + } + $contexts->require_one_edit_tab_cap($edittab); + } + + // ensure the files area exists for this course + make_upload_directory("$COURSE->id"); + + $import_form = new question_import_form($thispageurl, array('contexts'=>$contexts->having_one_edit_tab_cap('import'), + 'defaultcategory'=>$pagevars['cat'])); + + if ($import_form->is_cancelled()){ + redirect($thispageurl); + } + //========== + // PAGE HEADER + //========== + + if ($cm!==null) { + $strupdatemodule = has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE, $COURSE->id)) + ? update_module_button($cm->id, $COURSE->id, get_string('modulename', $cm->modname)) + : ""; + $navlinks = array(); + $navlinks[] = array('name' => get_string('modulenameplural', $cm->modname), 'link' => "$CFG->wwwroot/mod/{$cm->modname}/index.php?id=$COURSE->id", 'type' => 'activity'); + $navlinks[] = array('name' => format_string($module->name), 'link' => "$CFG->wwwroot/mod/{$cm->modname}/view.php?id={$cm->id}", 'type' => 'title'); + $navlinks[] = array('name' => $txt->importquestions, 'link' => '', 'type' => 'title'); + $navigation = build_navigation($navlinks); + print_header_simple($txt->importquestions, '', $navigation, "", "", true, $strupdatemodule); + + $currenttab = 'edit'; + $mode = 'import'; + ${$cm->modname} = $module; + include($CFG->dirroot."/mod/$cm->modname/tabs.php"); + } else { + // Print basic page layout. + $navlinks = array(); + $navlinks[] = array('name' => $txt->importquestions, 'link' => '', 'type' => 'title'); + $navigation = build_navigation($navlinks); + + print_header_simple($txt->importquestions, '', $navigation); + // print tabs + $currenttab = 'import'; + include('tabs.php'); + } + + + // file upload form sumitted + if ($form = $import_form->get_data()) { + + // file checks out ok + $fileisgood = false; + + // work out if this is an uploaded file + // or one from the filesarea. + if (!empty($form->choosefile)) { + $importfile = "{$CFG->dataroot}/{$COURSE->id}/{$form->choosefile}"; + $realfilename = $form->choosefile; + if (file_exists($importfile)) { + $fileisgood = true; + } else { + print_error('uploadproblem', 'moodle', $form->choosefile); + } + } else { + // must be upload file + $realfilename = $import_form->get_importfile_realname(); + if (!$importfile = $import_form->get_importfile_name()) { + print_error('uploadproblem', 'moodle'); + }else { + $fileisgood = true; + } + } + + // process if we are happy file is ok + if ($fileisgood) { + + if (! is_readable("format/$form->format/format.php")) { + print_error('formatnotfound','quiz', $form->format); + } + + require_once("format.php"); // Parent class + require_once("format/$form->format/format.php"); + + $classname = "qformat_$form->format"; + $qformat = new $classname(); + + // load data into class + $qformat->setCategory($category); + $qformat->setContexts($contexts->having_one_edit_tab_cap('import')); + $qformat->setCourse($COURSE); + $qformat->setFilename($importfile); + $qformat->setRealfilename($realfilename); + $qformat->setMatchgrades($form->matchgrades); + $qformat->setCatfromfile(!empty($form->catfromfile)); + $qformat->setContextfromfile(!empty($form->contextfromfile)); + $qformat->setStoponerror($form->stoponerror); + + // Do anything before that we need to + if (! $qformat->importpreprocess()) { + print_error('importerror', 'quiz', $thispageurl->out()); + } + + // Process the uploaded file + if (! $qformat->importprocess()) { + print_error('importerror', 'quiz', $thispageurl->out()); + } + + // In case anything needs to be done after + if (! $qformat->importpostprocess()) { + print_error('importerror', 'quiz', $thispageurl->out()); + } + + echo "
"; + print_continue("edit.php?".($thispageurl->get_query_string(array('category'=>"{$qformat->category->id},{$qformat->category->contextid}")))); + print_footer($COURSE); + exit; + } + } + + print_heading_with_help($txt->importquestions, "import", "quiz"); + + /// Print upload form + $import_form->display(); + print_footer($COURSE); + +?> Index: temp_moodle_dev/moodle/question/question.php =================================================================== diff -u --- temp_moodle_dev/moodle/question/question.php (revision 0) +++ temp_moodle_dev/moodle/question/question.php (revision b5e67f63747b4bb7072b78923d250396e77140f2) @@ -0,0 +1,244 @@ +libdir . '/filelib.php'); +require_once($CFG->libdir . '/formslib.php'); + +// Read URL parameters telling us which question to edit. +$id = optional_param('id', 0, PARAM_INT); // question id +$qtype = optional_param('qtype', '', PARAM_FILE); +$categoryid = optional_param('category', 0, PARAM_INT); + +$cmid = optional_param('cmid', 0, PARAM_INT); +$courseid = optional_param('courseid', 0, PARAM_INT); +$wizardnow = optional_param('wizardnow', '', PARAM_ALPHA); +$movecontext = optional_param('movecontext', 0, PARAM_BOOL);//switch to make question + //uneditable - form is displayed to edit category only +$returnurl = optional_param('returnurl', 0, PARAM_LOCALURL); + +$inpopup = optional_param('inpopup', 0, PARAM_BOOL); + +if ($movecontext && !$id){ + print_error('questiondoesnotexist', 'question', $returnurl); +} + +if ($cmid){ + list($module, $cm) = get_module_from_cmid($cmid); + require_login($cm->course, false, $cm); + $thiscontext = get_context_instance(CONTEXT_MODULE, $cmid); +} elseif ($courseid) { + require_login($courseid, false); + $thiscontext = get_context_instance(CONTEXT_COURSE, $courseid); + $module = null; + $cm = null; +} else { + error('Need to pass courseid or cmid to this script.'); +} +$contexts = new question_edit_contexts($thiscontext); + + +if (!$returnurl) { + $returnurl = "{$CFG->wwwroot}/question/edit.php?courseid={$COURSE->id}"; +} + + + +if ($id) { + if (!$question = get_record('question', 'id', $id)) { + print_error('questiondoesnotexist', 'question', $returnurl); + } + get_question_options($question); +} else if ($categoryid && $qtype) { // only for creating new questions + $question = new stdClass; + $question->category = $categoryid; + $question->qtype = $qtype; +} else { + print_error('notenoughdatatoeditaquestion', 'question', $returnurl); +} + +// Validate the question category. +if (!$category = get_record('question_categories', 'id', $question->category)) { + print_error('categorydoesnotexist', 'question', $returnurl); +} + +//permissions +$question->formoptions = new object(); + +$categorycontext = get_context_instance_by_id($category->contextid); +$addpermission = has_capability('moodle/question:add', $categorycontext); + +if ($id) { + $canview = question_has_capability_on($question, 'view'); + if ($movecontext){ + $question->formoptions->canedit = false; + $question->formoptions->canmove = (question_has_capability_on($question, 'move') && $contexts->have_cap('moodle/question:add')); + $question->formoptions->cansaveasnew = false; + $question->formoptions->repeatelements = false; + $question->formoptions->movecontext = true; + $formeditable = true; + question_require_capability_on($question, 'view'); + } else { + $question->formoptions->canedit = question_has_capability_on($question, 'edit'); + $question->formoptions->canmove = (question_has_capability_on($question, 'move') && $addpermission); + $question->formoptions->cansaveasnew = (($canview ||question_has_capability_on($question, 'edit')) && $addpermission); + $question->formoptions->repeatelements = ($question->formoptions->canedit || $question->formoptions->cansaveasnew); + $formeditable = $question->formoptions->canedit || $question->formoptions->cansaveasnew || $question->formoptions->canmove; + $question->formoptions->movecontext = false; + if (!$formeditable){ + question_require_capability_on($question, 'view'); + } + } + + +} else { // creating a new question + require_capability('moodle/question:add', $categorycontext); + $formeditable = true; + $question->formoptions->repeatelements = true; + $question->formoptions->movecontext = false; +} + + +// Validate the question type. +if (!isset($QTYPES[$question->qtype])) { + print_error('unknownquestiontype', 'question', $returnurl, $question->qtype); +} +$CFG->pagepath = 'question/type/' . $question->qtype; + + +// Create the question editing form. +if ($wizardnow!=='' && !$movecontext){ + if (!method_exists($QTYPES[$question->qtype], 'next_wizard_form')){ + print_error('missingimportantcode', 'question', $returnurl, 'wizard form definition'); + } else { + $mform = $QTYPES[$question->qtype]->next_wizard_form('question.php', $question, $wizardnow, $formeditable); + } +} else { + $mform = $QTYPES[$question->qtype]->create_editing_form('question.php', $question, $category, $contexts, $formeditable); +} +if ($mform === null) { + print_error('missingimportantcode', 'question', $returnurl, 'question editing form definition for "'.$question->qtype.'"'); +} +$toform = fullclone($question); // send the question object and a few more parameters to the form +$toform->category = "$category->id,$category->contextid"; +if ($formeditable && $id){ + $toform->categorymoveto = $toform->category; +} +$toform->returnurl = $returnurl; +$toform->movecontext = $movecontext; +if ($cm !== null){ + $toform->cmid = $cm->id; + $toform->courseid = $cm->course; +} else { + $toform->courseid = $COURSE->id; +} +$toform->inpopup = $inpopup; +$mform->set_data($toform); + +if ($mform->is_cancelled()){ + if ($inpopup) { + close_window(); + } else { + redirect($returnurl); + } +} elseif ($fromform = $mform->get_data()){ + $returnurl = new moodle_url($returnurl); + //select category that question has been saved in / moved to when we return to question bank + if (!empty($fromform->categorymoveto)){ + $returnurl->param('category', $fromform->categorymoveto); + } else if (!empty($fromform->category)){ + $returnurl->param('category', $fromform->category); + } + $returnurl = $returnurl->out(); + if (!empty($fromform->makecopy)) { + $question->id = 0; // causes a new question to be created. + $question->hidden = 0; // Copies should not be hidden + } + if ($movecontext){ + list($tocatid, $tocontextid) = explode(',', $fromform->categorymoveto); + $tocontext = get_context_instance_by_id($tocontextid); + require_capability('moodle/question:add', $tocontext); + if (get_filesdir_from_context($categorycontext) != get_filesdir_from_context($tocontext)){ + $movecontexturl = new moodle_url($CFG->wwwroot.'/question/contextmoveq.php', + array('returnurl' => $returnurl, + 'ids'=>$question->id, + 'tocatid'=> $tocatid)); + if ($cmid){ + $movecontexturl->param('cmid', $cmid); + } else { + $movecontexturl->param('courseid', $COURSE->id); + } + redirect($movecontexturl->out()); + } + } + + $question = $QTYPES[$question->qtype]->save_question($question, $fromform, $COURSE, $wizardnow); + if (($QTYPES[$question->qtype]->finished_edit_wizard($fromform)) || $movecontext){ + if ($inpopup) { + notify(get_string('changessaved'), ''); + close_window(3); + } else { + redirect($returnurl); + } + } else { + $nexturlparams = array('returnurl'=>$returnurl); + if (isset($fromform->nextpageparam) && is_array($fromform->nextpageparam)){ + $nexturlparams += $fromform->nextpageparam;//useful for passing data to the next page which is not saved in the database + } + $nexturlparams['id'] = $question->id; + $nexturlparams['wizardnow'] = $fromform->wizard; + $nexturl = new moodle_url('question.php', $nexturlparams); + if ($cmid){ + $nexturl->param('cmid', $cmid); + } else { + $nexturl->param('courseid', $COURSE->id); + } + redirect($nexturl->out()); + } +} else { + + list($streditingquestion,) = $QTYPES[$question->qtype]->get_heading(); + if ($cm !== null) { + $strmodule = get_string('modulename', $cm->modname); + $strupdatemodule = has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE, $COURSE->id)) + ? update_module_button($cm->id, $cm->course, $strmodule) + : ""; + + $streditingmodule = get_string('editinga', 'moodle', $strmodule); + + $navlinks = array(); + $navlinks[] = array('name' => get_string('modulenameplural', $cm->modname), 'link' => "$CFG->wwwroot/mod/{$cm->modname}/index.php?id=$cm->course", 'type' => 'activity'); + $navlinks[] = array('name' => format_string($module->name), 'link' => "$CFG->wwwroot/mod/{$cm->modname}/view.php?id={$cm->id}", 'type' => 'title'); + if (stripos($returnurl, "$CFG->wwwroot/mod/{$cm->modname}/view.php")!== 0){ + //don't need this link if returnurl returns to view.php + $navlinks[] = array('name' => $streditingmodule, 'link' => $returnurl, 'type' => 'title'); + } + $navlinks[] = array('name' => $streditingquestion, 'link' => '', 'type' => 'title'); + $navigation = build_navigation($navlinks); + print_header_simple($streditingquestion, '', $navigation, "", "", true, $strupdatemodule); + + } else { + $navlinks = array(); + $navlinks[] = array('name' => get_string('editquestions', "quiz"), 'link' => $returnurl, 'type' => 'title'); + $navlinks[] = array('name' => $streditingquestion, 'link' => '', 'type' => 'title'); + $strediting = ''. + get_string("editquestions", "quiz").' -> '.$streditingquestion; + $navigation = build_navigation($navlinks); + print_header_simple($streditingquestion, '', $navigation); + } + + + // Display a heading, question editing form and possibly some extra content needed for + // for this question type. + $QTYPES[$question->qtype]->display_question_editing_page($mform, $question, $wizardnow); + print_footer($COURSE); +} +?>