Пример #1
0
 /**
  * Sets up the edit page
  *
  * @param string $baseurl the base url of the
  *
  * @return array Array of variables that the page is set up with
  */
 public function setup_page($baseurl)
 {
     global $PAGE, $CFG, $DB;
     $this->pagevars = array();
     $pageurl = new \moodle_url($baseurl);
     $pageurl->remove_all_params();
     $id = optional_param('cmid', false, PARAM_INT);
     $quizid = optional_param('quizid', false, PARAM_INT);
     // get necessary records from the DB
     if ($id) {
         $cm = get_coursemodule_from_id('activequiz', $id, 0, false, MUST_EXIST);
         $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
         $quiz = $DB->get_record('activequiz', array('id' => $cm->instance), '*', MUST_EXIST);
     } else {
         $quiz = $DB->get_record('activequiz', array('id' => $quizid), '*', MUST_EXIST);
         $course = $DB->get_record('course', array('id' => $quiz->course), '*', MUST_EXIST);
         $cm = get_coursemodule_from_instance('activequiz', $quiz->id, $course->id, false, MUST_EXIST);
     }
     $this->get_parameters();
     // get the rest of the parameters and set them in the class
     if ($CFG->version < 2011120100) {
         $this->context = get_context_instance(CONTEXT_MODULE, $cm->id);
     } else {
         $this->context = \context_module::instance($cm->id);
     }
     // set up question lib
     list($this->pageurl, $this->contexts, $cmid, $cm, $quiz, $this->pagevars) = question_edit_setup('editq', '/mod/activequiz/edit.php', true);
     $PAGE->set_url($this->pageurl);
     $this->pagevars['pageurl'] = $this->pageurl;
     $PAGE->set_title(strip_tags($course->shortname . ': ' . get_string("modulename", "activequiz") . ': ' . format_string($quiz->name, true)));
     $PAGE->set_heading($course->fullname);
     // setup classes needed for the edit page
     $this->RTQ = new \mod_activequiz\activequiz($cm, $course, $quiz, $this->pagevars);
     $this->RTQ->get_renderer()->init($this->RTQ, $this->pageurl, $this->pagevars);
 }
Пример #2
0
        $attributes['disabled'] = $disabled ? 'disabled' : null;
        $select = html_writer::select($randomcount, 'randomcount', '1', null, $attributes);
        $out .= get_string('addrandom', 'quiz', $select);
        $out .= '<input type="hidden" name="recurse" value="' . $recurse . '" />';
        $out .= '<input type="hidden" name="categoryid" value="' . $category->id . '" />';
        $out .= ' <input type="submit" name="addrandom" value="' . get_string('addtoquiz', 'quiz') . '"' . $disabled . ' />';
        $out .= $OUTPUT->help_icon('addarandomquestion', 'quiz');
    }
    return $out;
}
// These params are only passed from page request to request while we stay on
// this page otherwise they would go in question_edit_setup.
$quiz_reordertool = optional_param('reordertool', -1, PARAM_BOOL);
$quiz_qbanktool = optional_param('qbanktool', -1, PARAM_BOOL);
$scrollpos = optional_param('scrollpos', '', PARAM_INT);
list($thispageurl, $contexts, $cmid, $cm, $quiz, $pagevars) = question_edit_setup('editq', '/mod/quiz/edit.php', true);
$quiz->questions = quiz_clean_layout($quiz->questions);
$defaultcategoryobj = question_make_default_categories($contexts->all());
$defaultcategory = $defaultcategoryobj->id . ',' . $defaultcategoryobj->contextid;
if ($quiz_qbanktool > -1) {
    $thispageurl->param('qbanktool', $quiz_qbanktool);
    set_user_preference('quiz_qbanktool_open', $quiz_qbanktool);
} else {
    $quiz_qbanktool = get_user_preferences('quiz_qbanktool_open', 0);
}
if ($quiz_reordertool > -1) {
    $thispageurl->param('reordertool', $quiz_reordertool);
    set_user_preference('quiz_reordertab', $quiz_reordertool);
} else {
    $quiz_reordertool = get_user_preferences('quiz_reordertab', 0);
}
<?php

// $Id: overview.php,v 1.3 2008/12/01 13:18:25 jamiesensei Exp $
/**
 * This page prints an overview of a particular instance of qcreate for someone with grading permission
 *
 * @author
 * @version $Id: overview.php,v 1.3 2008/12/01 13:18:25 jamiesensei Exp $
 * @package qcreate
 **/
require_once "../../config.php";
require_once $CFG->dirroot . '/mod/qcreate/lib.php';
require_once $CFG->dirroot . '/mod/qcreate/locallib.php';
require_once $CFG->dirroot . '/question/editlib.php';
list($thispageurl, $contexts, $cmid, $cm, $qcreate, $pagevars) = question_edit_setup('questions', true);
$qcreate->cmidnumber = $cm->id;
require_capability('mod/qcreate:grade', get_context_instance(CONTEXT_MODULE, $cm->id));
$requireds = get_records('qcreate_required', 'qcreateid', $qcreate->id, 'qtype', 'qtype, no, id');
$modulecontext = get_context_instance(CONTEXT_MODULE, $cm->id);
require_login($COURSE->id);
require_capability('mod/qcreate:grade', $modulecontext);
add_to_log($COURSE->id, "qcreate", "overview", "overview.php?id={$cm->id}", "{$qcreate->id}");
/// Print the page header
$strqcreates = get_string("modulenameplural", "qcreate");
$strqcreate = get_string("modulename", "qcreate");
$navlinks = array();
$navlinks[] = array('name' => $strqcreates, 'link' => "index.php?id={$COURSE->id}", 'type' => 'activity');
$navlinks[] = array('name' => format_string($qcreate->name), 'link' => '', 'type' => 'activityinstance');
$navigation = build_navigation($navlinks);
print_header_simple(format_string($qcreate->name), "", $navigation, "", "", true, update_module_button($cm->id, $COURSE->id, $strqcreate), navmenu($COURSE, $cm));
$mode = 'overview';
Пример #4
0
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
/**
 * Defines the import questions form.
 *
 * @package    moodlecore
 * @subpackage questionbank
 * @copyright  1999 onwards Martin Dougiamas  {@link http://moodle.com}
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
require_once __DIR__ . '/../config.php';
require_once $CFG->dirroot . '/question/editlib.php';
require_once $CFG->dirroot . '/question/import_form.php';
require_once $CFG->dirroot . '/question/format.php';
list($thispageurl, $contexts, $cmid, $cm, $module, $pagevars) = question_edit_setup('import', '/question/import.php');
// get display strings
$txt = new stdClass();
$txt->importerror = get_string('importerror', 'question');
$txt->importquestions = get_string('importquestions', 'question');
list($catid, $catcontext) = explode(',', $pagevars['cat']);
if (!($category = $DB->get_record("question_categories", array('id' => $catid)))) {
    print_error('nocategory', 'question');
}
$categorycontext = context::instance_by_id($category->contextid);
$category->context = $categorycontext;
//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($categorycontext);
 * (which is called from showbank())
 * Displays button in form with checkboxes for each question.
 */
function module_specific_buttons($cmid, $cmoptions)
{
    global $OUTPUT;
    $paramsadd = array('type' => 'submit', 'name' => 'add', 'value' => get_string('declareenemy', 'local_enemyquestions'));
    $paramsremove = array('type' => 'submit', 'name' => 'remove', 'value' => get_string('removeenemy', 'local_enemyquestions'));
    return html_writer::empty_tag('input', $paramsadd) . html_writer::empty_tag('input', $paramsremove);
}
// These params are only passed from page request to request while we stay on
// this page otherwise they would go in question_edit_setup.
$scrollpos = optional_param('scrollpos', '', PARAM_INT);
$qa = optional_param('qa', '', PARAM_INT);
$courseid = optional_param('courseid', false, PARAM_INT);
list($thispageurl, $contexts, $cmid, $cm, $quiz, $pagevars) = question_edit_setup('editq', '/local/enemyquestions/edit.php');
$defaultcategoryobj = question_make_default_categories($contexts->all());
$defaultcategory = $defaultcategoryobj->id . ',' . $defaultcategoryobj->contextid;
$thispageurl->param('qa', $qa);
$PAGE->set_url($thispageurl);
$PAGE->set_pagelayout('popup');
if (!$courseid) {
    $courseid = $quiz->course;
}
// Get the course object and related bits.
$course = $DB->get_record('course', array('id' => $courseid));
if (!$course) {
    print_error('invalidcourseid', 'error');
}
$questionbank = new local_enemyquestions_question_bank_view($contexts, $thispageurl, $course, $cm, $quiz);
// You need mod/quiz:manage in addition to question capabilities to access this page.
Пример #6
0
<?php

// $Id: contextmove.php,v 1.12 2008/11/27 11:50:29 tjhunt Exp $
/**
 * Allows someone with appropriate permissions to move a category and associated
 * files to another context.
 *
 * @author Jamie Pratt
 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
 * @package questionbank
 */
require_once "../config.php";
require_once $CFG->dirroot . "/question/editlib.php";
require_once $CFG->dirroot . "/question/contextmove_form.php";
list($thispageurl, $contexts, $cmid, $cm, $module, $pagevars) = question_edit_setup('categories');
// get values from form for actions on this page
$toparent = required_param('toparent', PARAM_SEQUENCE);
$cattomove = required_param('cattomove', PARAM_INT);
$totop = optional_param('totop', 0, PARAM_INT);
// optional param moves category to top of peers. Default is
//to add it to the bottom.
$onerrorurl = $CFG->wwwroot . '/question/category.php?' . $thispageurl->get_query_string();
list($toparent, $contextto) = explode(',', $toparent);
if (!empty($toparent)) {
    //not top level category, make it a child of $toparent
    if (!($toparent = $DB->get_record('question_categories', array('id' => $toparent)))) {
        print_error('invalidcategoryidforparent', 'question', $onerrorurl);
    }
    $contextto = $toparent->contextid;
} else {
    $toparent = new object();
Пример #7
0
// $Id: import.php,v 1.46.2.1 2007/11/02 16:20:12 tjhunt Exp $
/**
 * Import quiz questions into the given category
 *
 * @author Martin Dougiamas, Howard Miller, and many others.
 *         {@link http://moodle.org}
 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
 * @package questionbank
 * @subpackage importexport
 */
require_once "../config.php";
require_once "editlib.php";
require_once $CFG->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->importerror = get_string('importerror', 'quiz');
$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) {
Пример #8
0
        $out .= '<input type="hidden" name="categoryid" value="' . $category->id . '" />';
        $out .= ' <input type="submit" name="addrandom" value="'.
                get_string('addtoquiz', 'quiz').'"' . $disabled . ' />';
        $out .= $OUTPUT->help_icon('addarandomquestion', 'quiz');
    }
    return $out;
}

// These params are only passed from page request to request while we stay on
// this page otherwise they would go in question_edit_setup.
$quiz_reordertool = optional_param('reordertool', -1, PARAM_BOOL);
$quiz_qbanktool = optional_param('qbanktool', -1, PARAM_BOOL);
$scrollpos = optional_param('scrollpos', '', PARAM_INT);

list($thispageurl, $contexts, $cmid, $cm, $quiz, $pagevars) =
        question_edit_setup('editq', '/mod/quiz/edit.php', true);
$quiz->questions = quiz_clean_layout($quiz->questions);

$defaultcategoryobj = question_make_default_categories($contexts->all());
$defaultcategory = $defaultcategoryobj->id . ',' . $defaultcategoryobj->contextid;

if ($quiz_qbanktool > -1) {
    $thispageurl->param('qbanktool', $quiz_qbanktool);
    set_user_preference('quiz_qbanktool_open', $quiz_qbanktool);
} else {
    $quiz_qbanktool = get_user_preferences('quiz_qbanktool_open', 0);
}

if ($quiz_reordertool > -1) {
    $thispageurl->param('reordertool', $quiz_reordertool);
    set_user_preference('quiz_reordertab', $quiz_reordertool);
Пример #9
0
 * for users who do not use javascript.
 *
 * @package    mod
 * @subpackage quiz
 * @copyright  2008 Olli Savolainen
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */


require_once('../../config.php');
require_once($CFG->dirroot . '/mod/quiz/editlib.php');
require_once($CFG->dirroot . '/mod/quiz/addrandomform.php');
require_once($CFG->dirroot . '/question/category_class.php');

list($thispageurl, $contexts, $cmid, $cm, $quiz, $pagevars) =
        question_edit_setup('editq', '/mod/quiz/addrandom.php', true);

// These params are only passed from page request to request while we stay on
// this page otherwise they would go in question_edit_setup.
$returnurl = optional_param('returnurl', '', PARAM_LOCALURL);
$addonpage = optional_param('addonpage', 0, PARAM_INT);
$category = optional_param('category', 0, PARAM_INT);
$scrollpos = optional_param('scrollpos', 0, PARAM_INT);

// Get the course object and related bits.
if (!$course = $DB->get_record('course', array('id' => $quiz->course))) {
    print_error('invalidcourseid');
}
// You need mod/quiz:manage in addition to question capabilities to access this page.
// You also need the moodle/question:useall capability somewhere.
require_capability('mod/quiz:manage', $contexts->lowest());
Пример #10
0
 *
 * @package    moodlecore
 * @subpackage questionbank
 * @copyright  1999 onwards Martin Dougiamas  {@link http://moodle.com}
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */


require_once(dirname(__FILE__) . '/../config.php');
require_once($CFG->dirroot . '/question/editlib.php');
require_once($CFG->dirroot . '/question/export_form.php');

$PAGE->set_pagelayout('standard');

list($thispageurl, $contexts, $cmid, $cm, $module, $pagevars) =
        question_edit_setup('export', '/question/export.php');

// get display strings
$strexportquestions = get_string('exportquestions', 'question');

// make sure we are using the user's most recent category choice
if (empty($categoryid)) {
    $categoryid = $pagevars['cat'];
}

list($catid, $catcontext) = explode(',', $pagevars['cat']);
$category = $DB->get_record('question_categories', array("id" => $catid, 'contextid' => $catcontext), '*', MUST_EXIST);

/// Header
$PAGE->set_url($thispageurl->out());
$PAGE->set_title($strexportquestions);
Пример #11
0
    $url->param('cat', $cat);
}
if (($courseid = optional_param('courseid', 0, PARAM_INT)) !== 0) {
    $url->param('courseid', $courseid);
}
if (($returnurl = optional_param('returnurl', 0, PARAM_INT)) !== 0) {
    $url->param('returnurl', $returnurl);
}
if (($cmid = optional_param('cmid', 0, PARAM_INT)) !== 0) {
    $url->param('cmid', $cmid);
}
$PAGE->set_url($url);
$PAGE->set_pagelayout('standard');

list($thispageurl, $contexts, $cmid, $cm, $module, $pagevars) =
        question_edit_setup('questions', '/question/edit.php');
$questionbank = new question_bank_view($contexts, $thispageurl, $COURSE, $cm);
$questionbank->process_actions();

// TODO log this page view.

$context = $contexts->lowest();
$streditingquestions = get_string('editquestions', 'question');
$PAGE->set_title($streditingquestions);
$PAGE->set_heading($COURSE->fullname);
echo $OUTPUT->header();

echo '<div class="questionbankwindow boxwidthwide boxaligncenter">';
$questionbank->display('questions', $pagevars['qpage'],
        $pagevars['qperpage'], $pagevars['qsortorder'], $pagevars['qsortorderdecoded'],
        $pagevars['cat'], $pagevars['recurse'], $pagevars['showhidden'], $pagevars['showquestiontext']);
 private function get_categories()
 {
     $cmid = optional_param('cmid', 0, PARAM_INT);
     $categoryparam = optional_param('category', '', PARAM_TEXT);
     $courseid = optional_param('courseid', 0, PARAM_INT);
     if ($cmid) {
         list($thispageurl, $contexts, $cmid, $cm, $quiz, $pagevars) = question_edit_setup('editq', '/mod/quiz/edit.php', true);
         if ($pagevars['cat']) {
             $categoryparam = $pagevars['cat'];
         }
     }
     if ($categoryparam) {
         $catandcontext = explode(',', $categoryparam);
         $cats = question_categorylist($catandcontext[0]);
         return $cats;
     } else {
         if ($cmid) {
             list($module, $cm) = get_module_from_cmid($cmid);
             $courseid = $cm->course;
             require_login($courseid, false, $cm);
             $thiscontext = context_module::instance($cmid);
         } else {
             $module = null;
             $cm = null;
             if ($courseid) {
                 $thiscontext = context_course::instance($courseid);
             } else {
                 $thiscontext = null;
             }
         }
     }
     $cats = get_categories_for_contexts($thiscontext->id);
     return array_keys($cats);
 }
Пример #13
0
 * Fallback page of /mod/offlinequiz/edit.php add random question dialog,
 * for users who do not use javascript.
 *
 * @package       mod
 * @subpackage    offlinequiz
 * @author        Juergen Zimmer <*****@*****.**>
 * @copyright     2015 Academic Moodle Cooperation {@link http://www.academic-moodle-cooperation.org}
 * @since         Moodle 2.8+
 * @license       http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
require_once __DIR__ . '/../../config.php';
require_once $CFG->dirroot . '/mod/offlinequiz/locallib.php';
require_once $CFG->dirroot . '/mod/offlinequiz/addrandomform.php';
require_once $CFG->dirroot . '/question/editlib.php';
require_once $CFG->dirroot . '/question/category_class.php';
list($thispageurl, $contexts, $cmid, $cm, $offlinequiz, $pagevars) = question_edit_setup('editq', '/mod/offlinequiz/addrandom.php', true);
// These params are only passed from page request to request while we stay on
// this page otherwise they would go in question_edit_setup.
$returnurl = optional_param('returnurl', '', PARAM_LOCALURL);
$addonpage = optional_param('addonpage', 0, PARAM_INT);
$category = optional_param('category', 0, PARAM_INT);
$scrollpos = optional_param('scrollpos', 0, PARAM_INT);
$groupnumber = optional_param('groupnumber', 1, PARAM_INT);
// Get the course object and related bits.
if (!($course = $DB->get_record('course', array('id' => $offlinequiz->course)))) {
    print_error('invalidcourseid');
}
// You need mod/offlinequiz:manage in addition to question capabilities to access this page.
// You also need the moodle/question:useall capability somewhere.
require_capability('mod/offlinequiz:manage', $contexts->lowest());
if (!$contexts->having_cap('moodle/question:useall')) {
Пример #14
0
/**
 * This script allows a teacher to create, edit and delete question categories.
 *
 * @package    moodlecore
 * @subpackage questionbank
 * @copyright  1999 onwards Martin Dougiamas {@link http://moodle.com}
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */


require_once("../config.php");
require_once($CFG->dirroot."/question/editlib.php");
require_once($CFG->dirroot."/question/category_class.php");

list($thispageurl, $contexts, $cmid, $cm, $module, $pagevars) =
        question_edit_setup('categories', '/question/category.php');

// get values from form for actions on this page
$param = new stdClass();
$param->moveup = optional_param('moveup', 0, PARAM_INT);
$param->movedown = optional_param('movedown', 0, PARAM_INT);
$param->moveupcontext = optional_param('moveupcontext', 0, PARAM_INT);
$param->movedowncontext = optional_param('movedowncontext', 0, PARAM_INT);
$param->tocontext = optional_param('tocontext', 0, PARAM_INT);
$param->left = optional_param('left', 0, PARAM_INT);
$param->right = optional_param('right', 0, PARAM_INT);
$param->delete = optional_param('delete', 0, PARAM_INT);
$param->confirm = optional_param('confirm', 0, PARAM_INT);
$param->cancel = optional_param('cancel', '', PARAM_ALPHA);
$param->move = optional_param('move', 0, PARAM_INT);
$param->moveto = optional_param('moveto', 0, PARAM_INT);
Пример #15
0
<?php

// $Id: export.php,v 1.43.2.4 2008/09/15 14:21:02 thepurpleblob Exp $
/**
 * Export quiz questions into the given category
 *
 * @author Martin Dougiamas, Howard Miller, and many others.
 *         {@link http://moodle.org}
 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
 * @package questionbank
 * @subpackage importexport
 */
require_once "../config.php";
require_once "editlib.php";
require_once "export_form.php";
list($thispageurl, $contexts, $cmid, $cm, $module, $pagevars) = question_edit_setup('export');
// get display strings
$strexportquestions = get_string('exportquestions', 'quiz');
// make sure we are using the user's most recent category choice
if (empty($categoryid)) {
    $categoryid = $pagevars['cat'];
}
// ensure the files area exists for this course
make_upload_directory("{$COURSE->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)) : "";
Пример #16
0
 * Defines the import questions form.
 *
 * @package    moodlecore
 * @subpackage questionbank
 * @copyright  1999 onwards Martin Dougiamas  {@link http://moodle.com}
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */


require_once(dirname(__FILE__) . '/../config.php');
require_once($CFG->dirroot . '/question/editlib.php');
require_once($CFG->dirroot . '/question/import_form.php');
require_once($CFG->dirroot . '/question/format.php');

list($thispageurl, $contexts, $cmid, $cm, $module, $pagevars) =
        question_edit_setup('import', '/question/import.php', false, false);

// get display strings
$txt = new stdClass();
$txt->importerror = get_string('importerror', 'question');
$txt->importquestions = get_string('importquestions', 'question');

list($catid, $catcontext) = explode(',', $pagevars['cat']);
if (!$category = $DB->get_record("question_categories", array('id' => $catid))) {
    print_error('nocategory', 'question');
}

$PAGE->set_pagelayout('standard');

$categorycontext = get_context_instance_by_id($category->contextid);
$category->context = $categorycontext;