shortname: $strquestions", "$site->fullname",
"$stradministration -> ".
"$strconfiguration -> $strquestions");
print_heading($strquestions);
/// If data submitted, then process and store.
if (!empty($hide) and confirm_sesskey()) {
if (!$qtype = get_record("question_types", "name", $hide)) {
error("Question type doesn't exist!");
}
set_field("question_types", "visible", "0", "id", $qtype->id); // Hide question type
}
if (!empty($show) and confirm_sesskey()) {
if (!$qtype = get_record("question_types", "name", $show)) {
error("Question type doesn't exist!");
}
set_field("question_types", "visible", "1", "id", $qtype->id); // Show question type
}
if (!empty($delete) and confirm_sesskey()) {
$strqtypename = get_string("qtypename", "qtype_$delete");
if (!$confirm) {
notice_yesno(get_string("qtypedeleteconfirm", "admin", $strqtypename),
"questiontypes.php?delete=$delete&confirm=1&sesskey=$USER->sesskey",
"questiontypes.php");
print_footer();
exit;
} else { // Delete everything!!
if ($delete == "random") {
error("You can not delete the random question type!!");
}
if (!$qtype = get_record("question_types", "name", $delete)) {
error("Question type doesn't exist!");
}
// OK, first delete all the questions
if ($questions = get_records("quiz_questions", "qtype", $qtype->id)) {
foreach ($questions as $question) {
if (! quiz_delete_question($coursemod->id, $coursemod->section)) {
notify("Could not delete the $strqtypename with id = $question->id");
}
}
}
// And the qtype entry itself
if (!delete_records("question_types", "name", $qtype->name)) {
notify("Error occurred while deleting the $strqtypename record from question_types table");
}
// Then the tables themselves
if ($tables = $db->Metatables()) {
$prefix = $CFG->prefix.$qtype->name;
foreach ($tables as $table) {
if (strpos($table, $prefix) === 0) {
if (!execute_sql("DROP TABLE $table", false)) {
notify("ERROR: while trying to drop table $table");
}
}
}
}
$a->qtype = $strqtypename;
$a->directory = "$CFG->dirroot/qtype/$delete";
notice(get_string("qtypedeletefiles", "", $a), "questiontypes.php");
}
}
/// Get and sort the existing questiontypes
if (!$qtypes = get_records("question_types")) {
error("No question types found!!"); // Should never happen
}
foreach ($qtypes as $qtype) {
$strqtypename = get_string("qtypename", "qtype_$qtype->name");
$qtypebyname[$strqtypename] = $qtype;
}
ksort($qtypebyname);
/// Print the table of all questiontypes
$table->head = array ($strquestiontype, $strquestions, $strversion, "$strhide/$strshow", $strdelete, $strsettings);
$table->align = array ("left", "right", "left", "center", "center", "center");
$table->wrap = array ("nowrap", "", "", "", "","");
$table->size = array ("100%", "10", "10", "10", "10","12");
$table->width = "100";
foreach ($qtypebyname as $qtypename => $qtype) {
$icon = "
dirroot/mod/quiz/questiontypes/$qtype->name/icon.gif\" hspace=\"10\" height=\"16\" width=\"16\" border=\"0\" alt=\"\" />";
if (file_exists("$CFG->dirroot/mod/quiz/questiontypes/$qtype->name/config.html")) {
$settings = "name\">$strsettings";
} else {
$settings = "";
}
$count = count_records('quiz_questions', 'qtype', $qtype->id);
$delete = $count ? '' : "name&sesskey=$USER->sesskey\">$strdelete";
if ($qtype->visible) {
$visible = "name&sesskey=$USER->sesskey\" title=\"$strhide\">".
"
pixpath/i/hide.gif\" align=\"middle\" height=\"16\" width=\"16\" border=\"0\" alt=\"\" />";
$class = "";
} else {
$visible = "name&sesskey=$USER->sesskey\" title=\"$strshow\">".
"
pixpath/i/show.gif\" align=\"middle\" height=\"16\" width=\"16\" border=\"0\" alt=\"\" />";
$class = "class=\"dimmed_text\"";
}
if ($qtype->name == "random") {
$delete = "";
$visible = "";
$class = "";
}
$table->data[] = array ("$icon $qtypename", $count, $qtype->version, $visible, $delete, $settings);
}
print_table($table);
echo "
";
print_footer();
?>