function question_showbank_actions($pageurl, $cm)
{
    global $CFG, $COURSE;
    /// Now, check for commands on this page and modify variables as necessary
    if (optional_param('move', false, PARAM_BOOL) and confirm_sesskey()) {
        /// Move selected questions to new category
        $category = required_param('category', PARAM_SEQUENCE);
        list($tocategoryid, $contextid) = explode(',', $category);
        if (!($tocategory = get_record('question_categories', 'id', $tocategoryid, 'contextid', $contextid))) {
            error('Could not find category record');
        }
        $tocontext = get_context_instance_by_id($contextid);
        require_capability('moodle/question:add', $tocontext);
        $rawdata = (array) data_submitted();
        $questionids = array();
        foreach ($rawdata as $key => $value) {
            // Parse input for question ids
            if (preg_match('!^q([0-9]+)$!', $key, $matches)) {
                $key = $matches[1];
                $questionids[] = $key;
            }
        }
        if ($questionids) {
            $questionidlist = join($questionids, ',');
            $sql = "SELECT q.*, c.contextid FROM {$CFG->prefix}question q, {$CFG->prefix}question_categories c WHERE q.id IN ({$questionidlist}) AND c.id = q.category";
            if (!($questions = get_records_sql($sql))) {
                print_error('questiondoesnotexist', 'question', $pageurl->out());
            }
            $checkforfiles = false;
            foreach ($questions as $question) {
                //check capabilities
                question_require_capability_on($question, 'move');
                $fromcontext = get_context_instance_by_id($question->contextid);
                if (get_filesdir_from_context($fromcontext) != get_filesdir_from_context($tocontext)) {
                    $checkforfiles = true;
                }
            }
            $returnurl = $pageurl->out(false, array('category' => "{$tocategoryid},{$contextid}"));
            if (!$checkforfiles) {
                if (!question_move_questions_to_category(implode(',', $questionids), $tocategory->id)) {
                    print_error('errormovingquestions', 'question', $returnurl, $questionids);
                }
                redirect($returnurl);
            } else {
                $movecontexturl = new moodle_url($CFG->wwwroot . '/question/contextmoveq.php', array('returnurl' => $returnurl, 'ids' => $questionidlist, 'tocatid' => $tocategoryid));
                if ($cm) {
                    $movecontexturl->param('cmid', $cm->id);
                } else {
                    $movecontexturl->param('courseid', $COURSE->id);
                }
                redirect($movecontexturl->out());
            }
        }
    }
    if (optional_param('deleteselected', false, PARAM_BOOL)) {
        // delete selected questions from the category
        if ($confirm = optional_param('confirm', '', PARAM_ALPHANUM) and confirm_sesskey()) {
            // teacher has already confirmed the action
            $deleteselected = required_param('deleteselected');
            if ($confirm == md5($deleteselected)) {
                if ($questionlist = explode(',', $deleteselected)) {
                    // for each question either hide it if it is in use or delete it
                    foreach ($questionlist as $questionid) {
                        question_require_capability_on($questionid, 'edit');
                        if (record_exists('quiz_question_instances', 'question', $questionid)) {
                            if (!set_field('question', 'hidden', 1, 'id', $questionid)) {
                                question_require_capability_on($questionid, 'edit');
                                error('Was not able to hide question');
                            }
                        } else {
                            delete_question($questionid);
                        }
                    }
                }
                redirect($pageurl->out());
            } else {
                error("Confirmation string was incorrect");
            }
        }
    }
    // Unhide a question
    if ($unhide = optional_param('unhide', '', PARAM_INT) and confirm_sesskey()) {
        question_require_capability_on($unhide, 'edit');
        if (!set_field('question', 'hidden', 0, 'id', $unhide)) {
            error("Failed to unhide the question.");
        }
        redirect($pageurl->out());
    }
}
 function save_question_options($question)
 {
     global $QTYPES;
     $result = new stdClass();
     // This function needs to be able to handle the case where the existing set of wrapped
     // questions does not match the new set of wrapped questions so that some need to be
     // created, some modified and some deleted
     // Unfortunately the code currently simply overwrites existing ones in sequence. This
     // will make re-marking after a re-ordering of wrapped questions impossible and
     // will also create difficulties if questiontype specific tables reference the id.
     // First we get all the existing wrapped questions
     if (!($oldwrappedids = get_field('question_multianswer', 'sequence', 'question', $question->id))) {
         $oldwrappedquestions = array();
     } else {
         $oldwrappedquestions = get_records_list('question', 'id', $oldwrappedids, 'id ASC');
     }
     $sequence = array();
     foreach ($question->options->questions as $wrapped) {
         if (!empty($wrapped)) {
             // if we still have some old wrapped question ids, reuse the next of them
             if (is_array($oldwrappedquestions) && ($oldwrappedquestion = array_shift($oldwrappedquestions))) {
                 $wrapped->id = $oldwrappedquestion->id;
                 if ($oldwrappedquestion->qtype != $wrapped->qtype) {
                     switch ($oldwrappedquestion->qtype) {
                         case 'multichoice':
                             delete_records('question_multichoice', 'question', $oldwrappedquestion->id);
                             break;
                         case 'shortanswer':
                             delete_records('question_shortanswer', 'question', $oldwrappedquestion->id);
                             break;
                         case 'numerical':
                             delete_records('question_numerical', 'question', $oldwrappedquestion->id);
                             break;
                         default:
                             print_error('qtypenotrecognized', 'qtype_multianswer', '', $oldwrappedquestion->qtype);
                             $wrapped->id = 0;
                     }
                 }
             } else {
                 $wrapped->id = 0;
             }
         }
         $wrapped->name = $question->name;
         $wrapped->parent = $question->id;
         $previousid = $wrapped->id;
         $wrapped->category = $question->category . ',1';
         // save_question strips this extra bit off again.
         $wrapped = $QTYPES[$wrapped->qtype]->save_question($wrapped, $wrapped, $question->course);
         $sequence[] = $wrapped->id;
         if ($previousid != 0 && $previousid != $wrapped->id) {
             // for some reasons a new question has been created
             // so delete the old one
             delete_question($previousid);
         }
     }
     // Delete redundant wrapped questions
     if (is_array($oldwrappedquestions) && count($oldwrappedquestions)) {
         foreach ($oldwrappedquestions as $oldwrappedquestion) {
             delete_question($oldwrappedquestion->id);
         }
     }
     if (!empty($sequence)) {
         $multianswer = new stdClass();
         $multianswer->question = $question->id;
         $multianswer->sequence = implode(',', $sequence);
         if ($oldid = get_field('question_multianswer', 'id', 'question', $question->id)) {
             $multianswer->id = $oldid;
             if (!update_record("question_multianswer", $multianswer)) {
                 $result->error = "Could not update cloze question options! " . "(id={$multianswer->id})";
                 return $result;
             }
         } else {
             if (!insert_record("question_multianswer", $multianswer)) {
                 $result->error = "Could not insert cloze question options!";
                 return $result;
             }
         }
     }
 }
Exemple #3
0
}
if (isset($_REQUEST['deleteselected'])) {
    // delete selected questions from the category
    if (isset($_REQUEST['confirm']) and confirm_sesskey()) {
        // teacher has already confirmed the action
        $deleteselected = required_param('deleteselected');
        if ($_REQUEST['confirm'] == md5($deleteselected)) {
            if ($questionlist = explode(',', $deleteselected)) {
                // for each question either hide it if it is in use or delete it
                foreach ($questionlist as $questionid) {
                    if (record_exists('quiz_question_instances', 'question', $questionid)) {
                        if (!set_field('question', 'hidden', 1, 'id', $questionid)) {
                            error('Was not able to hide question');
                        }
                    } else {
                        delete_question($questionid);
                    }
                }
            }
            echo '</td></tr>';
            echo '</table>';
            echo '</div>';
            redirect("edit.php?courseid={$course->id}");
        } else {
            error("Confirmation string was incorrect");
        }
    } else {
        // teacher still has to confirm
        // make a list of all the questions that are selected
        $rawquestions = $_REQUEST;
        $questionlist = '';
Exemple #4
0
/**
 * All question categories and their questions are deleted for this activity.
 *
 * @param object $cm the course module object representing the activity
 * @param boolean $feedback to specify if the process must output a summary of its work
 * @return boolean
 */
function question_delete_activity($cm, $feedback = true)
{
    //To store feedback to be showed at the end of the process
    $feedbackdata = array();
    //Cache some strings
    $strcatdeleted = get_string('unusedcategorydeleted', 'quiz');
    $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
    if ($categoriesmods = get_records('question_categories', 'contextid', $modcontext->id, 'parent', 'id, parent, name')) {
        //Sort categories following their tree (parent-child) relationships
        //this will make the feedback more readable
        $categoriesmods = sort_categories_by_tree($categoriesmods);
        foreach ($categoriesmods as $category) {
            //Delete it completely (questions and category itself)
            //deleting questions
            if ($questions = get_records("question", "category", $category->id)) {
                foreach ($questions as $question) {
                    delete_question($question->id);
                }
                delete_records("question", "category", $category->id);
            }
            //delete the category
            delete_records('question_categories', 'id', $category->id);
            //Fill feedback
            $feedbackdata[] = array($category->name, $strcatdeleted);
        }
        //Inform about changes performed if feedback is enabled
        if ($feedback) {
            $table = new stdClass();
            $table->head = array(get_string('category', 'quiz'), get_string('action'));
            $table->data = $feedbackdata;
            print_table($table);
        }
    }
    return true;
}
Exemple #5
0
}
//dbconnect("localhost", "quizuser", "quiz", "quiz");
$row = get_quiz($_GET['edit']);
// make update
if (isset($_POST['update'])) {
    $subject_id = $_POST['subject_id'];
    $title = $_POST['title'];
    $duration = $_POST['duration'];
    $number_of_questions = $_POST['num_of_ques'];
    $status = $_POST['status'];
    //print_r($_POST);
    update_quiz($_GET['edit'], $subject_id, $title, $duration, $number_of_questions, $status);
    //redirect_to('allquestions.php?qid='.$_GET['edit']);
}
if (isset($_POST['delete_question'])) {
    delete_question($_GET['quid']);
    redirect_to('edit.php?edit=' . $_GET['edit']);
}
?>

<div class="container">
<a href="question.php?qid=<?php 
echo $_GET['edit'];
?>
"><i class="fa fa-question fa-lg fa-fw"></i>Add new question</a>

    <h1>update quiz</h1>
    <form class="form-horizontal" method="POST" action="edit.php?edit=<?php 
echo $_GET['edit'];
?>
">
function RWSDQCat($r_qci)
{
    global $DB;
    global $CFG;
    $r_chn = $DB->get_records("question_categories", array("parent" => $r_qci));
    if (count($r_chn) > 0) {
        foreach ($r_chn as $r_chd) {
            RWSDQCat($r_chd->id);
        }
    }
    $r_qsts = $DB->get_records("question", array("category" => $r_qci));
    if (count($r_qsts) > 0) {
        foreach ($r_qsts as $r_q) {
            if (respondusws_floatcompare($CFG->version, 2011070100, 2) >= 0) {
                question_delete_question($r_q->id);
            } else {
                delete_question($r_q->id);
            }
        }
        $DB->delete_records("question", array("category" => $r_qci));
    }
    $DB->delete_records("question_categories", array("id" => $r_qci));
}
Exemple #7
0
         $max = $_POST[MIN] == "" ? 0 : $_POST[MAX];
         $msg = add_reponse($_POST[ID], $_POST[LIBELE], $min, $max);
     }
     break;
 case DELETE_SONDAGE:
     if (!isset($_GET[ID])) {
         $msg = ERROR_CORRUPTED_DATA;
     } else {
         $msg = delete_sondage($_GET[ID]);
     }
     break;
 case DELETE_QUESTION:
     if (!isset($_GET[ID])) {
         $msg = ERROR_CORRUPTED_DATA;
     } else {
         $msg = delete_question($_GET[ID]);
     }
     break;
 case DELETE_USER:
     if (!isset($_GET[ID])) {
         $msg = ERROR_CORRUPTED_DATA;
     } else {
         $msg = delete_compte_as_admin($_GET[ID]);
     }
     break;
 case DELETE_REPONSE:
     if (!isset($_GET[ID])) {
         $msg = ERROR_CORRUPTED_DATA;
     } else {
         $msg = delete_reponse($_GET[ID]);
     }
                                 <?php 
                 }
             }
         }
     }
     ?>
                 </div>
             <?php 
 } else {
     if (isset($_POST['save'])) {
         $question = $_POST['question_text'];
         $id = $_POST['question_id'];
         save_question($id, $question);
     } else {
         if (isset($_POST['delete'])) {
             delete_question($_POST['question_id']);
         } else {
             if (isset($_POST['add']) && !empty($_POST['question'])) {
                 add_question($_POST['question'], $_POST['category']);
             } else {
                 ?>
                 <div id="questions">
                     <?php 
                 $categories = get_categories();
                 if ($categories) {
                     foreach ($categories as $category) {
                         ?>
                             <table>
                                 <thead>
                                 <tr>
                                     <td colspan="3"><h3><?php 
/**
 * All non-used question categories and their questions are deleted and
 * categories still used by other courses are moved to the site course.
 *
 * @param object $course an object representing the course
 * @param boolean $feedback to specify if the process must output a summary of its work
 * @return boolean
 */
function question_delete_course($course, $feedback = true)
{
    global $CFG, $QTYPES;
    //To detect if we have created the "container category"
    $concatid = 0;
    //The "container" category we'll create if we need if
    $contcat = new object();
    //To temporary store changes performed with parents
    $parentchanged = array();
    //To store feedback to be showed at the end of the process
    $feedbackdata = array();
    //Cache some strings
    $strcatcontainer = get_string('containercategorycreated', 'quiz');
    $strcatmoved = get_string('usedcategorymoved', 'quiz');
    $strcatdeleted = get_string('unusedcategorydeleted', 'quiz');
    if ($categories = get_records('question_categories', 'course', $course->id, 'parent', 'id, parent, name, course')) {
        //Sort categories following their tree (parent-child) relationships
        $categories = sort_categories_by_tree($categories);
        foreach ($categories as $cat) {
            //Get the full record
            $category = get_record('question_categories', 'id', $cat->id);
            //Check if the category is being used anywhere
            if (question_category_isused($category->id, true)) {
                //It's being used. Cannot delete it, so:
                //Create a container category in SITEID course if it doesn't exist
                if (!$concatid) {
                    $concat = new stdClass();
                    $concat->course = SITEID;
                    if (!isset($course->shortname)) {
                        $course->shortname = 'id=' . $course->id;
                    }
                    $concat->name = get_string('savedfromdeletedcourse', 'quiz', format_string($course->shortname));
                    $concat->info = $concat->name;
                    $concat->publish = 1;
                    $concat->stamp = make_unique_id_code();
                    $concatid = insert_record('question_categories', $concat);
                    //Fill feedback
                    $feedbackdata[] = array($concat->name, $strcatcontainer);
                }
                //Move the category to the container category in SITEID course
                $category->course = SITEID;
                //Assign to container if the category hasn't parent or if the parent is wrong (not belongs to the course)
                if (!$category->parent || !isset($categories[$category->parent])) {
                    $category->parent = $concatid;
                }
                //If it's being used, its publish field should be 1
                $category->publish = 1;
                //Let's update it
                update_record('question_categories', $category);
                //Save this parent change for future use
                $parentchanged[$category->id] = $category->parent;
                //Fill feedback
                $feedbackdata[] = array($category->name, $strcatmoved);
            } else {
                //Category isn't being used so:
                //Delete it completely (questions and category itself)
                //deleting questions
                if ($questions = get_records("question", "category", $category->id)) {
                    foreach ($questions as $question) {
                        delete_question($question->id);
                    }
                    delete_records("question", "category", $category->id);
                }
                //delete the category
                delete_records('question_categories', 'id', $category->id);
                //Save this parent change for future use
                if (!empty($category->parent)) {
                    $parentchanged[$category->id] = $category->parent;
                } else {
                    $parentchanged[$category->id] = $concatid;
                }
                //Update all its child categories to re-parent them to grandparent.
                set_field('question_categories', 'parent', $parentchanged[$category->id], 'parent', $category->id);
                //Fill feedback
                $feedbackdata[] = array($category->name, $strcatdeleted);
            }
        }
        //Inform about changes performed if feedback is enabled
        if ($feedback) {
            $table = new stdClass();
            $table->head = array(get_string('category', 'quiz'), get_string('action'));
            $table->data = $feedbackdata;
            print_table($table);
        }
    }
    return true;
}
Exemple #10
0
<?php

include 'header.html';
require_once '../includes/db_conn.php';
require_once 'admin_fun.php';
if (isset($_POST['question_title']) && isset($_POST['key']) && isset($_POST['mark']) && isset($_POST['question_url'])) {
    $question_title = $_POST['question_title'];
    $key = $_POST['key'];
    $mark = $_POST['mark'];
    $type = $_POST['type'];
    $quesion_url = $_POST['question_url'];
    $quesion_id = $_POST['question_id'];
    insert_question($question_id, $question_title, $key, $mark, $type, $question_url);
}
if (isset($_GET['delid'])) {
    delete_question($_GET['delid']);
}
?>

<script type="text/javascript">
	function del(){
		var mymessage=confirm("确认删除吗?");
		if(confirm(mymessage)==true){ 
			return true;
		}else{ 
			return false;
		} 
	}
</script>
<br>
<br>
Exemple #11
0
 public function process_actions()
 {
     global $CFG, $DB;
     /// Now, check for commands on this page and modify variables as necessary
     if (optional_param('move', false, PARAM_BOOL) and confirm_sesskey()) {
         // Move selected questions to new category
         $category = required_param('category', PARAM_SEQUENCE);
         list($tocategoryid, $contextid) = explode(',', $category);
         if (!($tocategory = $DB->get_record('question_categories', array('id' => $tocategoryid, 'contextid' => $contextid)))) {
             print_error('cannotfindcate', 'question');
         }
         $tocontext = get_context_instance_by_id($contextid);
         require_capability('moodle/question:add', $tocontext);
         $rawdata = (array) data_submitted();
         $questionids = array();
         foreach ($rawdata as $key => $value) {
             // Parse input for question ids
             if (preg_match('!^q([0-9]+)$!', $key, $matches)) {
                 $key = $matches[1];
                 $questionids[] = $key;
             }
         }
         if ($questionids) {
             list($usql, $params) = $DB->get_in_or_equal($questionids);
             $sql = "";
             $questions = $DB->get_records_sql("\n                        SELECT q.*, c.contextid\n                        FROM {question} q\n                        JOIN {question_categories} c ON c.id = q.category\n                        WHERE q.id {$usql}", $params);
             foreach ($questions as $question) {
                 question_require_capability_on($question, 'move');
             }
             question_move_questions_to_category($questionids, $tocategory->id);
             redirect($this->baseurl->out(false, array('category' => "{$tocategoryid},{$contextid}")));
         }
     }
     if (optional_param('deleteselected', false, PARAM_BOOL)) {
         // delete selected questions from the category
         if ($confirm = optional_param('confirm', '', PARAM_ALPHANUM) and confirm_sesskey()) {
             // teacher has already confirmed the action
             $deleteselected = required_param('deleteselected', PARAM_RAW);
             if ($confirm == md5($deleteselected)) {
                 if ($questionlist = explode(',', $deleteselected)) {
                     // for each question either hide it if it is in use or delete it
                     foreach ($questionlist as $questionid) {
                         $questionid = (int) $questionid;
                         question_require_capability_on($questionid, 'edit');
                         if ($DB->record_exists('quiz_question_instances', array('question' => $questionid))) {
                             $DB->set_field('question', 'hidden', 1, array('id' => $questionid));
                         } else {
                             delete_question($questionid);
                         }
                     }
                 }
                 redirect($this->baseurl);
             } else {
                 print_error('invalidconfirm', 'question');
             }
         }
     }
     // Unhide a question
     if ($unhide = optional_param('unhide', '', PARAM_INT) and confirm_sesskey()) {
         question_require_capability_on($unhide, 'edit');
         $DB->set_field('question', 'hidden', 0, array('id' => $unhide));
         redirect($this->baseurl);
     }
 }
<?php

include "designtemplate.php";
include "database.php";
include "validation.php";
verify_authorization("admin");
connect();
?>

<?php 
if (isset($_POST['deletequestions'])) {
    foreach ($_POST as $key => $value) {
        $arr = explode("_", $key);
        if ($arr[0] == 'checkbox') {
            delete_question($arr[1]);
        }
    }
}
?>

<html>
	<head>
		<title>
			Question Bank
		</title>
	</head>
	
	<body>
	
		<?php 
connect();
                 exit(get_particlesystem_by_id($request[1]));
             }
             if ($requestSize == 3) {
                 if ($request[2] == "") {
                     exit(get_particlesystem_by_id($request[1]));
                 }
             }
             handle_error();
         default:
             handle_error();
     }
     break;
 case 'DELETE':
     switch ($request[0]) {
         case 'questions':
             exit(delete_question($request[1]));
         case 'particlesystems':
             exit(delete_particlesystem($request[1]));
         default:
             handle_error();
     }
     break;
 case 'POST':
     switch ($request[0]) {
         case 'particlesystems':
             save_particle_system();
             exit("");
         case 'questions':
             save_question();
             exit("");
         default: