*
 * @package   mod_activequiz
 * @author    John Hoopes <*****@*****.**>
 * @copyright 2014 University of Wisconsin - Madison
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
define('AJAX_SCRIPT', true);
require_once '../../config.php';
require_sesskey();
// if they've passed the sesskey information grab the session info
$sessionid = required_param('sessionid', PARAM_INT);
// get JSONlib to return json response
$jsonlib = new \mod_activequiz\utils\jsonlib();
// First determine if we get a session.
if (!($session = $DB->get_record('activequiz_sessions', array('id' => $sessionid)))) {
    $jsonlib->send_error('invalid session');
}
// Next we need to get the active quiz object and course module object to make sure a student can log in
// for the session asked for
if (!($activequiz = $DB->get_record('activequiz', array('id' => $session->activequizid)))) {
    $jsonlib->send_error('invalid request');
} else {
    // place within try/catch in order to catch errors/redirects and just display invalid request.
    try {
        $course = $DB->get_record('course', array('id' => $activequiz->course), '*', MUST_EXIST);
        $cm = get_coursemodule_from_instance('activequiz', $activequiz->id, $course->id, false, MUST_EXIST);
        require_login($course->id, false, $cm, false, true);
    } catch (Exception $e) {
        $jsonlib->send_error('invalid request');
    }
}
Beispiel #2
0
 /**
  * Handles the action specified
  *
  */
 public function handle_action()
 {
     global $PAGE, $DB;
     // check if a session is open.  If so display error.
     if ($sessions = $DB->get_records('activequiz_sessions', array('activequizid' => $this->RTQ->getRTQ()->id, 'sessionopen' => '1'))) {
         $this->RTQ->get_renderer()->print_editpage_header();
         $this->RTQ->get_renderer()->editpage_opensession();
         $this->RTQ->get_renderer()->end_editpage();
         return;
         // return early to stop continuation.
     }
     switch ($this->action) {
         case 'dragdrop':
             // this is a javascript callack case for the drag and drop of questions using ajax
             $jsonlib = new \mod_activequiz\utils\jsonlib();
             $questionorder = optional_param('questionorder', '', PARAM_RAW);
             if ($questionorder === '') {
                 $jsonlib->send_error('invalid request');
             }
             $questionorder = explode(',', $questionorder);
             if ($this->RTQ->get_questionmanager()->set_full_order($questionorder) === true) {
                 $jsonlib->set('success', 'true');
                 $jsonlib->send_response();
             } else {
                 $jsonlib->send_error('unable to re-sort questions');
             }
             break;
         case 'moveup':
             $questionid = required_param('questionid', PARAM_INT);
             if ($this->RTQ->get_questionmanager()->move_question('up', $questionid)) {
                 $type = 'success';
                 $message = get_string('qmovesuccess', 'activequiz');
             } else {
                 $type = 'error';
                 $message = get_string('qmoveerror', 'activequiz');
             }
             $this->RTQ->get_renderer()->setMessage($type, $message);
             $this->RTQ->get_renderer()->print_editpage_header($this->RTQ);
             $this->list_questions();
             $this->RTQ->get_renderer()->end_editpage();
             break;
         case 'movedown':
             $questionid = required_param('questionid', PARAM_INT);
             if ($this->RTQ->get_questionmanager()->move_question('down', $questionid)) {
                 $type = 'success';
                 $message = get_string('qmovesuccess', 'activequiz');
             } else {
                 $type = 'error';
                 $message = get_string('qmoveerror', 'activequiz');
             }
             $this->RTQ->get_renderer()->setMessage($type, $message);
             $this->RTQ->get_renderer()->print_editpage_header($this->RTQ);
             $this->list_questions();
             $this->RTQ->get_renderer()->end_editpage();
             break;
         case 'addquestion':
             $questionid = required_param('questionid', PARAM_INT);
             $this->RTQ->get_questionmanager()->add_question($questionid);
             break;
         case 'editquestion':
             $questionid = required_param('rtqquestionid', PARAM_INT);
             $this->RTQ->get_questionmanager()->edit_question($questionid);
             break;
         case 'deletequestion':
             $questionid = required_param('questionid', PARAM_INT);
             if ($this->RTQ->get_questionmanager()->delete_question($questionid)) {
                 $type = 'success';
                 $message = get_string('qdeletesucess', 'activequiz');
             } else {
                 $type = 'error';
                 $message = get_string('qdeleteerror', 'activequiz');
             }
             $this->RTQ->get_renderer()->setMessage($type, $message);
             $this->RTQ->get_renderer()->print_editpage_header($this->RTQ);
             $this->list_questions();
             $this->RTQ->get_renderer()->end_editpage();
             break;
         case 'listquestions':
             // default is to list the questions
             $this->RTQ->get_renderer()->print_editpage_header($this->RTQ);
             $this->list_questions();
             $this->RTQ->get_renderer()->end_editpage();
             break;
     }
 }