/**
  * Run all the question tests for all variants of all questions belonging to
  * a given context.
  *
  * Does output as we go along.
  *
  * @param context $context the context to run the tests for.
  * @return array with two elements:
  *              bool true if all the tests passed, else false.
  *              array of messages relating to the questions with failures.
  */
 public function run_all_tests_for_context(context $context)
 {
     global $DB, $OUTPUT;
     // Load the necessary data.
     $categories = question_category_options(array($context));
     $categories = reset($categories);
     $questiontestsurl = new moodle_url('/question/type/stack/questiontestrun.php');
     if ($context->contextlevel == CONTEXT_COURSE) {
         $questiontestsurl->param('courseid', $context->instanceid);
     } else {
         if ($context->contextlevel == CONTEXT_MODULE) {
             $questiontestsurl->param('cmid', $context->instanceid);
         }
     }
     $allpassed = true;
     $failingtests = array();
     foreach ($categories as $key => $category) {
         list($categoryid) = explode(',', $key);
         echo $OUTPUT->heading($category, 3);
         $questionids = $DB->get_records_menu('question', array('category' => $categoryid, 'qtype' => 'stack'), 'name', 'id,name');
         if (!$questionids) {
             continue;
         }
         echo html_writer::tag('p', stack_string('replacedollarscount', count($questionids)));
         foreach ($questionids as $questionid => $name) {
             $tests = question_bank::get_qtype('stack')->load_question_tests($questionid);
             if (!$tests) {
                 echo $OUTPUT->heading(html_writer::link(new moodle_url($questiontestsurl, array('questionid' => $questionid)), format_string($name)), 4);
                 echo html_writer::tag('p', stack_string('bulktestnotests'));
                 continue;
             }
             $question = question_bank::load_question($questionid);
             $questionname = format_string($name);
             $previewurl = new moodle_url($questiontestsurl, array('questionid' => $questionid));
             if (empty($question->deployedseeds)) {
                 $questionnamelink = html_writer::link($previewurl, $questionname);
                 echo $OUTPUT->heading($questionnamelink, 4);
                 list($ok, $message) = $this->qtype_stack_test_question($question, $tests);
                 if (!$ok) {
                     $allpassed = false;
                     $failingtests[] = $questionnamelink . ': ' . $message;
                 }
             } else {
                 echo $OUTPUT->heading(format_string($name), 4);
                 foreach ($question->deployedseeds as $seed) {
                     $previewurl->param('seed', $seed);
                     $questionnamelink = html_writer::link($previewurl, stack_string('seedx', $seed));
                     echo $OUTPUT->heading($questionnamelink, 4);
                     list($ok, $message) = $this->qtype_stack_test_question($question, $tests, $seed);
                     if (!$ok) {
                         $allpassed = false;
                         $failingtests[] = $questionname . ' ' . $questionnamelink . ': ' . $message;
                     }
                 }
             }
         }
     }
     return array($allpassed, $failingtests);
 }
 /**
  * Constructor
  *
  * @param string $elementName Select name attribute
  * @param mixed $elementLabel Label(s) for the select
  * @param array $options additional options. Recognised options are courseid, published and
  *              only_editable, corresponding to the arguments of question_category_options
  *              from moodlelib.php.
  * @param mixed $attributes Either a typical HTML attribute string or an associative array
  */
 public function __construct($elementName = null, $elementLabel = null, $options = null, $attributes = null)
 {
     parent::__construct($elementName, $elementLabel, array(), $attributes);
     $this->_type = 'questioncategory';
     if (is_array($options)) {
         $this->_options = $options + $this->_options;
         $this->loadArrayOptGroups(question_category_options($this->_options['contexts'], $this->_options['top'], $this->_options['currentcat'], false, $this->_options['nochildrenof']));
     }
 }
 /**
  * Called by HTML_QuickForm whenever form event is made on this element
  *
  * @param string $event Name of event
  * @param mixed $arg event arguments
  * @param object $caller calling object
  * @access public
  * @return mixed
  */
 function onQuickFormEvent($event, $arg, &$caller)
 {
     switch ($event) {
         case 'createElement':
             $this->load(question_category_options($this->_courseid, $this->_published, $this->_only_editable));
             break;
     }
     return parent::onQuickFormEvent($event, $arg, $caller);
 }
 /**
  * Constructor
  *
  * @param string $elementName Select name attribute
  * @param mixed $elementLabel Label(s) for the select
  * @param array $options additional options. Recognised options are courseid, published and
  *              only_editable, corresponding to the arguments of question_category_options
  *              from moodlelib.php.
  * @param mixed $attributes Either a typical HTML attribute string or an associative array
  */
 function MoodleQuickForm_questioncategory($elementName = null, $elementLabel = null, $options = null, $attributes = null)
 {
     MoodleQuickForm_selectgroups::MoodleQuickForm_selectgroups($elementName, $elementLabel, array(), $attributes);
     $this->_type = 'questioncategory';
     if (is_array($options)) {
         $this->_options = $options + $this->_options;
         $this->loadArrayOptGroups(question_category_options($this->_options['contexts'], $this->_options['top'], $this->_options['currentcat'], false, $this->_options['nochildrenof']));
     }
 }
Exemple #5
0
/**
 * prints a form to choose categories
 */
function question_category_form($contexts, $pageurl, $current, $recurse = 1, $showhidden = false, $showquestiontext = false)
{
    global $CFG;
    /// Get all the existing categories now
    $catmenu = question_category_options($contexts, false, 0, true);
    $strcategory = get_string('category', 'quiz');
    $strshow = get_string('show', 'quiz');
    $streditcats = get_string('editcategories', 'quiz');
    popup_form('edit.php?' . $pageurl->get_query_string() . '&amp;category=', $catmenu, 'catmenu', $current, '', '', '', false, 'self', "<strong>{$strcategory}</strong>");
    echo '<form method="get" action="edit.php" id="displayoptions">';
    echo "<fieldset class='invisiblefieldset'>";
    echo $pageurl->hidden_params_out(array('recurse', 'showhidden', 'showquestiontext'));
    question_category_form_checkbox('recurse', $recurse);
    question_category_form_checkbox('showhidden', $showhidden);
    question_category_form_checkbox('showquestiontext', $showquestiontext);
    echo '<noscript><div class="centerpara"><input type="submit" value="' . get_string('go') . '" />';
    echo '</div></noscript></fieldset></form>';
}
    /**
     * Display the drop down to select the category.
     *
     * @param array $contexts of contexts that can be accessed from here.
     * @param \moodle_url $pageurl the URL of this page.
     * @param string $current 'categoryID,contextID'.
     */
    protected function display_category_form($contexts, $pageurl, $current) {
        global $OUTPUT;

        echo \html_writer::start_div('choosecategory');
        $catmenu = question_category_options($contexts, false, 0, true);
        $select = new \single_select($this->baseurl, 'category', $catmenu, $current, null, 'catmenu');
        $select->set_label(get_string('selectacategory', 'question'));
        echo $OUTPUT->render($select);
        echo \html_writer::end_div() . "\n";
    }
Exemple #7
0
 /**
  * Prints a form to choose categories
  * @deprecated since Moodle 2.7 MDL-40313.
  * @see \core_question\bank\search\condition
  * @todo MDL-41978 This will be deleted in Moodle 2.8
  */
 protected function display_category_form($contexts, $pageurl, $current)
 {
     global $OUTPUT;
     debugging('display_category_form() is deprecated, please use ' . '\\core_question\\bank\\search\\condition instead.', DEBUG_DEVELOPER);
     // Get all the existing categories now.
     echo '<div class="choosecategory">';
     $catmenu = question_category_options($contexts, false, 0, true);
     $select = new \single_select($this->baseurl, 'category', $catmenu, $current, null, 'catmenu');
     $select->set_label(get_string('selectacategory', 'question'));
     echo $OUTPUT->render($select);
     echo "</div>\n";
 }
Exemple #8
0
        // In case anything needs to be done after
        if (!$qformat->importpostprocess()) {
            error($txt->importerror, "{$CFG->wwwroot}/question/import.php?courseid={$course->id}&amp;category={$category->id}");
        }
        echo "<hr />";
        print_continue("edit.php?courseid={$course->id}");
        print_footer($course);
        exit;
    }
}
/// Print upload form
// get list of available import formats
$fileformatnames = get_import_export_formats('import');
print_heading_with_help($txt->importquestions, "import", "quiz");
/// Get all the existing categories now
$catmenu = question_category_options($course->id, false, true);
//==========
// DISPLAY
//==========
?>

    <form id="form" enctype="multipart/form-data" method="post" action="import.php">
        <fieldset class="invisiblefieldset" style="display: block;">
            <input type="hidden" name="sesskey" value="<?php 
echo sesskey();
?>
" />
            <input type="hidden" name="courseid" value="<?php 
echo $localcourseid;
?>
" />
Exemple #9
0
/**
 * Output a select menu of question categories.
 *
 * Categories from this course and (optionally) published categories from other courses
 * are included. Optionally, only categories the current user may edit can be included.
 *
 * @param integer $courseid the id of the course to get the categories for.
 * @param integer $published if true, include publised categories from other courses.
 * @param integer $only_editable if true, exclude categories this user is not allowed to edit.
 * @param integer $selected optionally, the id of a category to be selected by default in the dropdown.
 */
function question_category_select_menu($contexts, $top = false, $currentcat = 0, $selected = "", $nochildrenof = -1)
{
    global $OUTPUT;
    $categoriesarray = question_category_options($contexts, $top, $currentcat, false, $nochildrenof);
    if ($selected) {
        $nothing = '';
    } else {
        $nothing = 'choosedots';
    }
    $select = html_select::make($categoriesarray, 'category', $selected);
    $select->nothingvalue = $nothing;
    $select->nested = true;
    echo $OUTPUT->select($select);
}
Exemple #10
0
/**
 * Output a select menu of question categories.
 *
 * Categories from this course and (optionally) published categories from other courses
 * are included. Optionally, only categories the current user may edit can be included.
 *
 * @param integer $courseid the id of the course to get the categories for.
 * @param integer $published if true, include publised categories from other courses.
 * @param integer $only_editable if true, exclude categories this user is not allowed to edit.
 * @param integer $selected optionally, the id of a category to be selected by default in the dropdown.
 */
function question_category_select_menu($contexts, $top = false, $currentcat = 0, $selected = "", $nochildrenof = -1)
{
    $categoriesarray = question_category_options($contexts, $top, $currentcat, false, $nochildrenof);
    if ($selected) {
        $nothing = '';
    } else {
        $nothing = 'choose';
    }
    choose_from_menu_nested($categoriesarray, 'category', $selected, $nothing);
}
Exemple #11
0
}
if (!($category = get_record("question_categories", "id", $categoryid))) {
    $category = get_default_question_category($courseid);
}
if (!($categorycourse = get_record("course", "id", $category->course))) {
    print_error('nocategory', 'quiz');
}
require_login($course->id, false);
// check role capability
$context = get_context_instance(CONTEXT_COURSE, $course->id);
require_capability('moodle/question:export', $context);
// ensure the files area exists for this course
make_upload_directory("{$course->id}");
// check category is valid
if (!empty($categoryid)) {
    $validcats = question_category_options($course->id, true, false);
    if (!array_key_exists($categoryid, $validcats)) {
        print_error('invalidcategory', 'quiz');
    }
}
/// Header
if (isset($SESSION->modform->instance) and $quiz = get_record('quiz', 'id', $SESSION->modform->instance)) {
    $strupdatemodule = has_capability('moodle/course:manageactivities', $context) ? update_module_button($SESSION->modform->cmid, $course->id, $txt->modulename) : "";
    print_header_simple($txt->exportquestions, '', "<a href=\"{$CFG->wwwroot}/mod/quiz/index.php?id={$course->id}\">{$txt->modulenameplural}</a>" . " -> <a href=\"{$CFG->wwwroot}/mod/quiz/view.php?q={$quiz->id}\">" . format_string($quiz->name) . '</a>' . ' -> ' . $txt->exportquestions, "", "", true, $strupdatemodule);
    $currenttab = 'edit';
    $mode = 'export';
    include $CFG->dirroot . '/mod/quiz/tabs.php';
} else {
    print_header_simple($txt->exportquestions, '', $txt->exportquestions);
    // print tabs
    $currenttab = 'export';
Exemple #12
0
/**
 * Output a select menu of question categories.
 *
 * Categories from this course and (optionally) published categories from other courses
 * are included. Optionally, only categories the current user may edit can be included.
 *
 * @param integer $courseid the id of the course to get the categories for.
 * @param integer $published if true, include publised categories from other courses.
 * @param integer $only_editable if true, exclude categories this user is not allowed to edit.
 * @param integer $selected optionally, the id of a category to be selected by default in the dropdown.
 */
function question_category_select_menu($courseid, $published = false, $only_editable = false, $selected = "")
{
    $categoriesarray = question_category_options($courseid, $published, $only_editable);
    if ($selected) {
        $nothing = '';
    } else {
        $nothing = 'choose';
    }
    choose_from_menu($categoriesarray, 'category', $selected, $nothing);
}
Exemple #13
0
 /**
  * prints a form to choose categories
  */
 protected function display_category_form($contexts, $pageurl, $current)
 {
     global $CFG;
     /// Get all the existing categories now
     echo '<div class="choosecategory">';
     $catmenu = question_category_options($contexts, false, 0, true);
     popup_form('edit.php?' . $pageurl->get_query_string() . '&amp;category=', $catmenu, 'catmenu', $current, '', '', '', false, 'self', get_string('selectacategory', 'question'));
     echo "</div>\n";
 }
Exemple #14
0
/**
 * Output a select menu of question categories.
 *
 * Categories from this course and (optionally) published categories from other courses
 * are included. Optionally, only categories the current user may edit can be included.
 *
 * @param integer $courseid the id of the course to get the categories for.
 * @param integer $published if true, include publised categories from other courses.
 * @param integer $only_editable if true, exclude categories this user is not allowed to edit.
 * @param integer $selected optionally, the id of a category to be selected by
 *      default in the dropdown.
 */
function question_category_select_menu($contexts, $top = false, $currentcat = 0, $selected = "", $nochildrenof = -1)
{
    global $OUTPUT;
    $categoriesarray = question_category_options($contexts, $top, $currentcat, false, $nochildrenof);
    if ($selected) {
        $choose = '';
    } else {
        $choose = 'choosedots';
    }
    $options = array();
    foreach ($categoriesarray as $group => $opts) {
        $options[] = array($group => $opts);
    }
    echo html_writer::label(get_string('questioncategory', 'core_question'), 'id_movetocategory', false, array('class' => 'accesshide'));
    $attrs = array('id' => 'id_movetocategory', 'class' => 'custom-select');
    echo html_writer::select($options, 'category', $selected, $choose, $attrs);
}
Exemple #15
0
    /**
     * prints a form to choose categories
     */
    protected function display_category_form($contexts, $pageurl, $current) {
        global $CFG, $OUTPUT;

    /// Get all the existing categories now
        echo '<div class="choosecategory">';
        $catmenu = question_category_options($contexts, false, 0, true);

        $select = new single_select($this->baseurl, 'category', $catmenu, $current, null, 'catmenu');
        $select->set_label(get_string('selectacategory', 'question'));
        echo $OUTPUT->render($select);
        echo "</div>\n";
    }
 function importprocess($filename)
 {
     global $CFG, $USER, $strimportquestions, $form, $question_category, $category, $COURSE, $hostname, $mdapath, $mdbpath;
     if (PHP_OS == "Linux" and isset($hostname)) {
         $hostname = trim($hostname);
         // test the ODBC socket server connection
         // if failure, unset hostname and set hostname_access_error
         $question_categories = $this->getquestioncategories($mdbpath, $mdapath, $hostname);
         if (!$question_categories) {
             $hostname_access_error = $hostname . " ";
             unset($hostname);
         } else {
             $hostname_access_error = 0;
         }
     }
     if (PHP_OS == "Linux" and !isset($hostname)) {
         // copy the file to a semi-permanent location
         if (!($basedir = make_upload_directory("{$COURSE->id}"))) {
             error("The site administrator needs to fix the file permissions for the data directory");
         }
         if (!isset($hostname_access_error)) {
             $bname = basename($filename);
             $cleanfilename = clean_filename($bname);
             if ($cleanfilename) {
                 $newfile = "{$basedir}/{$cleanfilename}";
                 if (move_uploaded_file($filename, $newfile)) {
                     chmod($newfile, 0666);
                     clam_log_upload($newfile, $COURSE);
                 } else {
                     notify(get_string("uploadproblem", "", $filename));
                 }
             }
             $filename = $newfile;
         }
         print_heading_with_help($strimportquestions, "import", "quiz");
         print_simple_box_start("center");
         if ($hostname_access_error) {
             notify("couldn't connect to ODBC Socket Server on " . $hostname_access_error);
         }
         echo "<form method=\"post\" action=\"import.php\">";
         echo '<fieldset class="invisiblefieldset">';
         echo "<table cellpadding=\"5\">";
         echo "<tr><td align=\"right\">";
         echo "What is the hostname or IP address of the ODBC Socket Server:</td><td>";
         echo " <input name=\"hostname\" type=\"text\" size=\"50\" value=\"" . stripslashes($hostname_access_error) . "\" />";
         echo " <input name=\"filename\" type=\"hidden\" value=\"" . $filename . "\" />";
         echo " <input name=\"category\" type=\"hidden\" value=\"" . $category->id . "\" />";
         echo " <input name=\"format\" type=\"hidden\" value=\"" . $form->format . "\" />";
         echo "</td><td>&nbsp;</td></tr>";
         echo "<tr><td align=\"right\">";
         echo "What is the location of the database (.mdb file) on the Socket Server:</td><td>";
         echo " <input name=\"mdbpath\" type=\"text\" size=\"50\" value=\"" . stripslashes($mdbpath) . "\" />";
         echo "</td><td>&nbsp;</td></tr>";
         echo "<tr><td align=\"right\">";
         echo "What is the location of the system database (System.mda file) on the Socket Server:</td><td>";
         echo " <input name=\"mdapath\" type=\"text\" size=\"50\" value=\"" . stripslashes($mdapath) . "\" />";
         echo "</td><td>&nbsp;</td></tr>";
         echo "<tr><td>&nbsp;</td><td>";
         echo " <input type=\"submit\" name=\"save\" value=\"Connect to Server\" />";
         echo "</td></tr>";
         echo "</table>";
         echo '</fieldset>';
         echo "</form>";
         print_simple_box_end();
         print_footer($COURSE);
         exit;
     }
     // we get here if running windows or after connect to ODBC socket server on linux
     //
     // this generates the page to choose categories of questions to import
     //
     if (!isset($question_category)) {
         if (PHP_OS == "WINNT") {
             // copy the file to a semi-permanent location
             if (!($basedir = make_upload_directory("{$COURSE->id}"))) {
                 error("The site administrator needs to fix the file permissions for the data directory");
             }
             $bname = basename($filename);
             $cleanfilename = clean_filename($bname);
             if ($cleanfilename) {
                 $newfile = "{$basedir}/{$cleanfilename}";
                 if (move_uploaded_file($filename, $newfile)) {
                     chmod($newfile, 0666);
                     clam_log_upload($newfile, $COURSE);
                 } else {
                     notify(get_string("uploadproblem", "", $filename));
                 }
             }
             $filename = $newfile;
         }
         // end of file copy
         // don't have to do this on linux, since it's alreay been done in the test above
         if (PHP_OS == "WINNT") {
             $question_categories = $this->getquestioncategories($filename);
         }
         // print the intermediary form
         if (!($categories = question_category_options($COURSE->id, true))) {
             error("No categories!");
         }
         print_heading_with_help($strimportquestions, "import", "quiz");
         print_simple_box_start("center");
         echo "<form method=\"post\" action=\"import.php\">";
         echo '<fieldset class="invisiblefieldset">';
         echo "<table cellpadding=\"5\">";
         echo "<tr><td align=\"right\">";
         echo "Choose a category of questions to import:</td><td>";
         asort($question_categories);
         choose_from_menu($question_categories, "question_category", "All Categories", "All Categories", "", "allcategories");
         echo " <input name=\"filename\" type=\"hidden\" value=\"" . $filename . "\" />";
         echo " <input name=\"category\" type=\"hidden\" value=\"" . $category->id . "\" />";
         echo " <input name=\"format\" type=\"hidden\" value=\"" . $form->format . "\" />";
         if (PHP_OS == "Linux") {
             echo " <input name=\"hostname\" type=\"hidden\" value=\"" . stripslashes(trim($hostname)) . "\" />";
             echo " <input name=\"mdbpath\" type=\"hidden\" value=\"" . stripslashes($mdbpath) . "\" />";
             echo " <input name=\"mdapath\" type=\"hidden\" value=\"" . stripslashes($mdapath) . "\" />";
         }
         echo "</td><td>&nbsp;</td>";
         echo "</tr><tr><td>&nbsp;</td><td>";
         echo " <input type=\"submit\" name=\"save\" value=\"Import Questions\" />";
         echo "</td></tr>";
         echo "</table>";
         echo '</fieldset>';
         echo "</form>";
         print_simple_box_end();
         print_footer($COURSE);
         exit;
     }
     //
     // this is the main import section
     //
     notify("Importing questions");
     if (PHP_OS == "Linux") {
         $hostname = trim($hostname);
         $records = $this->getquestions($mdbpath, $question_category, $mdapath, $hostname);
     } else {
         $records = $this->getquestions($filename, $question_category);
     }
     foreach ($records as $qrec) {
         $question = $this->defaultquestion();
         if ($qrec[9] != "") {
             $question->image = $qrec[9];
         }
         //  0   Selected
         //  1   PracticeTestOK?
         //  2   QuestionText
         //  3   QuestionType
         //  4   Option1Text
         //  5   Option2Text
         //  6   Option3Text
         //  7   Option4Text
         //  8   CorrectAnswer
         //  9   Graphic
         //  10  Module
         //  11  ChapterNumber
         //  12  PageNumber
         $ref = "Answer can be found in chapter " . $qrec[11] . ", page " . $qrec[12] . ".";
         switch ($qrec[3]) {
             case 1:
                 $question->qtype = MULTICHOICE;
                 // MULTICHOICE, SHORTANSWER, TRUEFALSE
                 //          echo "<pre>";echo htmlspecialchars($qrec[2]); echo "</pre>";
                 $question->questiontext = addslashes(trim($qrec[2]));
                 //          echo "<pre>";echo $question->questiontext; echo "</pre>";
                 $question->name = preg_replace("/<br />/", "", $question->questiontext);
                 $question->single = 1;
                 // Only one answer is allowed -- used for multiple choicers
                 $fractionset = 0;
                 for ($i = 4; $i <= 7; $i++) {
                     if ($qrec[$i] != "") {
                         $question->answer[$i - 3] = addslashes($qrec[$i]);
                         if ($qrec[8] == $i - 3) {
                             // if this is the index of CorrectAnswer
                             $question->fraction[$i - 3] = 1;
                             $fractionset = 1;
                         } else {
                             $question->fraction[$i - 3] = 0;
                         }
                         $question->feedback[$i - 3] = ($qrec[8] == $i - 3 ? "Correct. " : "Incorrect. ") . $ref;
                     }
                 }
                 if ($fractionset == 0) {
                     $question->fraction[1] = 1;
                 }
                 break;
             case 2:
                 // TRUE FALSE
                 $question->qtype = TRUEFALSE;
                 $question->questiontext = addslashes(trim($qrec[2]));
                 $question->name = preg_replace("/<br />/", "", $question->questiontext);
                 // for TF, $question->answer should be 1 for true, 0 for false
                 if ($qrec[8] == "T") {
                     $question->answer = 1;
                 } else {
                     $question->answer = 0;
                 }
                 // for TF, use $question->feedbacktrue and feedbackfalse
                 $question->feedbacktrue = ($qrec[8] == "T" ? "Correct. " : "Incorrect. ") . $ref;
                 $question->feedbackfalse = ($qrec[8] == "F" ? "Correct. " : "Incorrect. ") . $ref;
                 break;
             case 3:
                 $question->qtype = SHORTANSWER;
                 $question->questiontext = addslashes(trim($qrec[2]));
                 //          echo "<pre>";echo $question->questiontext; echo "</pre>";
                 $question->name = preg_replace("/<br />/", "", $question->questiontext);
                 $question->usecase = 0;
                 // Ignore case -- for SHORT ANSWER questions
                 $answers = explode("~", $qrec[8]);
                 $question->answer[0] = " ";
                 $question->fraction[0] = 1;
                 for ($i = 0; $i < count($answers); $i++) {
                     $question->answer[$i] = addslashes(trim($answers[$i]));
                     $question->feedback[$i] = $ref;
                     $question->fraction[$i] = 1;
                     // 1 for 100%, 0 for none or somewhere in between
                 }
                 break;
             case 4:
                 $question = 0;
                 notify("Cannot use essay questions - skipping question " . $qrec[2] . " " . $ref);
                 break;
             default:
                 $question = 0;
                 notify("Misformatted Record.  Question Skipped.");
                 break;
         }
         if ($question) {
             $questions[] = $question;
         }
     }
     $count = 0;
     // process all the questions
     if (PHP_OS == "WINNT") {
         $filename = str_replace("\\\\", "\\", $filename);
         $filename = str_replace("/", "\\", $filename);
     }
     foreach ($questions as $question) {
         // Process and store each question
         $count++;
         echo "<hr /><p><b>{$count}</b>. " . stripslashes($question->questiontext) . "</p>";
         $question->category = $this->category->id;
         $question->stamp = make_unique_id_code();
         // Set the unique code (not to be changed)
         $question->createdby = $USER->id;
         $question->timecreated = time();
         if (!($question->id = insert_record("question", $question))) {
             error("Could not insert new question!");
         }
         $this->questionids[] = $question->id;
         // Now to save all the answers and type-specific options
         $result = save_question_options($question);
         if (!empty($result->error)) {
             notify($result->error);
             $this->deletedatabase($filename);
             return false;
         }
         if (!empty($result->notice)) {
             notify($result->notice);
             $this->deletedatabase($filename);
             return true;
         }
         // Give the question a unique version stamp determined by question_hash()
         set_field('question', 'version', question_hash($question), 'id', $question->id);
     }
     $this->deletedatabase($filename);
     return true;
 }
require_once $CFG->libdir . '/questionlib.php';
require_once __DIR__ . '/locallib.php';
require_once __DIR__ . '/stack/utils.class.php';
// Get the parameters from the URL.
$contextid = required_param('contextid', PARAM_INT);
$confirm = optional_param('confirm', false, PARAM_BOOL);
// Login and check permissions.
$context = context::instance_by_id($contextid);
require_login();
require_capability('moodle/site:config', $context);
$PAGE->set_url('/question/type/stack/replacedollars.php', array('contextid' => $context->id));
$PAGE->set_context($context);
$title = stack_string('replacedollarstitle', $context->get_context_name());
$PAGE->set_title($title);
// Load the necessary data.
$categories = question_category_options(array($context));
$categories = reset($categories);
$fixer = new qtype_stack_dollar_fixer();
$questionfields = array('questiontext', 'generalfeedback');
$qtypestackfields = array('specificfeedback', 'prtcorrect', 'prtpartiallycorrect', 'prtincorrect', 'questionnote');
$prtnodefields = array('truefeedback', 'falsefeedback');
$qafields = array('questionsummary', 'rightanswer', 'responsesummary');
$anychanges = false;
// Display.
echo $OUTPUT->header();
echo $OUTPUT->heading($title);
foreach ($categories as $key => $category) {
    list($categoryid) = explode(',', $key);
    echo $OUTPUT->heading($category, 3);
    $questions = $DB->get_records('question', array('category' => $categoryid, 'qtype' => 'stack'), 'id');
    echo html_writer::tag('p', stack_string('replacedollarscount', count($questions)));
/**
 * Output a select menu of question categories.
 *
 * Categories from this course and (optionally) published categories from other courses
 * are included. Optionally, only categories the current user may edit can be included.
 *
 * @param integer $courseid the id of the course to get the categories for.
 * @param integer $published if true, include publised categories from other courses.
 * @param integer $only_editable if true, exclude categories this user is not allowed to edit.
 * @param integer $selected optionally, the id of a category to be selected by
 *      default in the dropdown.
 */
function question_category_select_menu($contexts, $top = false, $currentcat = 0, $selected = "", $nochildrenof = -1)
{
    global $OUTPUT;
    $categoriesarray = question_category_options($contexts, $top, $currentcat, false, $nochildrenof);
    if ($selected) {
        $choose = '';
    } else {
        $choose = 'choosedots';
    }
    $options = array();
    foreach ($categoriesarray as $group => $opts) {
        $options[] = array($group => $opts);
    }
    echo html_writer::label($selected, 'menucategory', false, array('class' => 'accesshide'));
    echo html_writer::select($options, 'category', $selected, $choose);
}
Exemple #19
0
 /**
  * Display the drop down to select the category.
  *
  * @param array $contexts of contexts that can be accessed from here.
  * @param \moodle_url $pageurl the URL of this page.
  * @param string $current 'categoryID,contextID'.
  */
 protected function display_category_form($contexts, $pageurl, $current)
 {
     global $OUTPUT;
     echo \html_writer::start_div('choosecategory');
     $catmenu = question_category_options($contexts, false, 0, true);
     echo \html_writer::label(get_string('selectacategory', 'question'), 'id_selectacategory');
     echo \html_writer::select($catmenu, 'category', $current, array(), array('class' => 'searchoptions', 'id' => 'id_selectacategory'));
     echo \html_writer::end_div() . "\n";
 }
Exemple #20
0
/**
 * prints a form to choose categories
 */
function question_category_form($course, $current, $recurse = 1, $showhidden = false, $showquestiontext = false)
{
    global $CFG;
    /// Make sure the default category exists for this course
    get_default_question_category($course->id);
    /// Get all the existing categories now
    $catmenu = question_category_options($course->id, true);
    $strcategory = get_string("category", "quiz");
    $strshow = get_string("show", "quiz");
    $streditcats = get_string("editcategories", "quiz");
    echo "<table><tr><td style=\"white-space:nowrap;\">";
    echo "<strong>{$strcategory}:</strong>&nbsp;";
    echo "</td><td>";
    popup_form("edit.php?courseid={$course->id}&amp;cat=", $catmenu, "catmenu", $current, "", "", "", false, "self");
    echo "</td><td align=\"right\">";
    echo "<form method=\"get\" action=\"{$CFG->wwwroot}/question/category.php\">";
    echo "<div>";
    echo "<input type=\"hidden\" name=\"id\" value=\"{$course->id}\" />";
    echo "<input type=\"submit\" value=\"{$streditcats}\" />";
    echo '</div>';
    echo "</form>";
    echo '</td></tr></table>';
    echo '<form method="get" action="edit.php" id="displayoptions">';
    echo "<fieldset class='invisiblefieldset'>";
    echo "<input type=\"hidden\" name=\"courseid\" value=\"{$course->id}\" />\n";
    question_category_form_checkbox('recurse', $recurse);
    question_category_form_checkbox('showhidden', $showhidden);
    question_category_form_checkbox('showquestiontext', $showquestiontext);
    echo '<noscript><div class="centerpara"><input type="submit" value="' . get_string('go') . '" />';
    echo '</div></noscript></fieldset></form>';
}
Exemple #21
0
 /**
  * prints a form to choose categories
  */
 protected function display_category_form($contexts, $pageurl, $current)
 {
     global $CFG, $OUTPUT;
     /// Get all the existing categories now
     echo '<div class="choosecategory">';
     $catmenu = question_category_options($contexts, false, 0, true);
     $select = html_select::make_popup_form('edit.php?' . $pageurl->get_query_string(), 'category', $catmenu, 'catmenu', $current);
     $select->nothinglabel = false;
     $select->set_label(get_string('selectacategory', 'question'));
     echo $OUTPUT->select($select);
     echo "</div>\n";
 }