⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mysql.php

📁 很棒的在线教学系统
💻 PHP
📖 第 1 页 / 共 5 页
字号:
                $sequence = array();                $positions = array();                // Turn reporting off temporarily to avoid one line output per set_field                global $db;                $olddebug = $db->debug;                $db->debug = false;                echo 'Now updating '.$n.' cloze questions.';                for ($i = 0; $i < $n; $i++) {                    // Backup these two values before unsetting the object fields                    $answers = $multianswers[$i]->answers; unset($multianswers[$i]->answers);                    $pos = $multianswers[$i]->positionkey; unset($multianswers[$i]->positionkey);                    // Needed for substituting multianswer ids with position keys in the $state->answer field                    $positions[$multianswers[$i]->id] = $pos;                // Create questions for all the multianswer victims                    unset($multianswers[$i]->id);                    $multianswers[$i]->length = 0;                    $multianswers[$i]->questiontext = '';                    $multianswers[$i]->stamp = make_unique_id_code();                    $multianswers[$i]->name = addslashes($multianswers[$i]->name);                    // $multianswers[$i]->parent is set in the query                    // $multianswers[$i]->defaultgrade is set in the query                    // $multianswers[$i]->qtype is set in the query                    $id = insert_record('quiz_questions', $multianswers[$i]);                    $success = $success && $id;                    $sequence[$pos] = $id;                // Update the quiz_answers table to point to these new questions                $success = $success && execute_sql("UPDATE {$CFG->prefix}quiz_answers SET question = '$id' WHERE id IN ($answers)", false);                // Update the questiontype tables to point to these new questions                    if (SHORTANSWER == $multianswers[$i]->qtype) {                        $success = $success && execute_sql("UPDATE {$CFG->prefix}quiz_shortanswer SET question = '$id' WHERE answers = '$answers'", false);                    } else if (MULTICHOICE == $multianswers[$i]->qtype) {                        $success = $success && execute_sql("UPDATE {$CFG->prefix}quiz_multichoice SET question = '$id' WHERE answers = '$answers'", false);                    } else if (NUMERICAL == $multianswers[$i]->qtype) {                        $success = $success && execute_sql("UPDATE {$CFG->prefix}quiz_numerical SET question = '$id' WHERE answer IN ($answers)", false);                    }                    // Whenever we're through with the subquestions of one multianswer                    // question we delete the old records in the multianswers table,                    // store a new record with the sequence in the multianswers table                    // and point $parent to the next multianswer question.                    if (!isset($multianswers[$i+1]) || $parent != $multianswers[$i+1]->parent) {                        // Substituting multianswer ids with position keys in the $state->answer field                        if ($states = get_records('quiz_states', 'question', $parent)) {                            foreach ($states as $state) {                                $reg = array();                                preg_match_all('/(?:^|,)([0-9]+)-([^,]*)/', $state->answer, $reg);                                $state->answer = '';                                $m = count($reg[1]);                                for ($j = 0; $j < $m; $j++) {                                    if (isset($positions[$reg[1][$j]])) {                                        $state->answer .= $positions[$reg[1][$j]] . '-' . $reg[2][$j] . ',';                                    } else {                                        notify("Undefined multianswer id ({$reg[1][$j]}) used in state #{$state->id}!");                                        $state->answer .= $j+1 . '-' . $reg[2][$j] . ',';                                    }                                }                                $state->answer = rtrim($state->answer, ','); // strip trailing comma                                $success = $success && update_record('quiz_states', $state);                            }                        }                        $success = $success && delete_records('quiz_multianswers', 'question', $parent);                        $multi = new stdClass;                        $multi->question = $parent;                        $multi->sequence = implode(',', $sequence);                        $success = $success && insert_record('quiz_multianswers', $multi);                        if (isset($multianswers[$i+1])) {                            $parent    = $multianswers[$i+1]->parent;                            $sequence  = array();                            $positions = array();                        }                    }                }                $db->debug = $olddebug;            }            // Remove redundant fields from quiz_multianswers            $success = $success && modify_database('', 'ALTER TABLE `prefix_quiz_multianswers` DROP `answers`');            $success = $success && modify_database('', 'ALTER TABLE `prefix_quiz_multianswers` DROP `positionkey`');            $success = $success && modify_database('', 'ALTER TABLE `prefix_quiz_multianswers` DROP `answertype`');            $success = $success && modify_database('', 'ALTER TABLE `prefix_quiz_multianswers` DROP `norm`');        }    }    if ($success && $oldversion < 2005052004) {        // We need to remove some duplicate entries that may be present in some databases        // due to a faulty restore script        // Remove duplicate entries from quiz_numerical        if ($dups = get_records_sql("                SELECT question, answer, count(*) as num                FROM {$CFG->prefix}quiz_numerical                GROUP BY question, answer                HAVING count(*) > 1"            )) {            foreach ($dups as $dup) {                $ids = get_records_sql("                    SELECT id, id                    FROM {$CFG->prefix}quiz_numerical                    WHERE question = '$dup->question'                    AND answer = '$dup->answer'"                );                $skip = true;                foreach ($ids as $id) {                    if ($skip) {                        $skip = false;                    } else {                        $success = $success && delete_records('quiz_numerical','id', $id->id);                    }                }            }        }        // Remove duplicate entries from quiz_shortanswer        if ($dups = get_records_sql("                SELECT question, answers, count(*) as num                FROM {$CFG->prefix}quiz_shortanswer                GROUP BY question, answers                HAVING count(*) > 1"            )) {            foreach ($dups as $dup) {                $ids = get_records_sql("                    SELECT id, id                    FROM {$CFG->prefix}quiz_shortanswer                    WHERE question = '$dup->question'                    AND answers = '$dup->answers'"                );                $skip = true;                foreach ($ids as $id) {                    if ($skip) {                        $skip = false;                    } else {                        $success = $success && delete_records('quiz_shortanswer','id', $id->id);                    }                }            }        }        // Remove duplicate entries from quiz_multichoice        if ($dups = get_records_sql("                SELECT question, answers, count(*) as num                FROM {$CFG->prefix}quiz_multichoice                GROUP BY question, answers                HAVING count(*) > 1"            )) {            foreach ($dups as $dup) {                $ids = get_records_sql("                    SELECT id, id                    FROM {$CFG->prefix}quiz_multichoice                    WHERE question = '$dup->question'                    AND answers = '$dup->answers'"                );                $skip = true;                foreach ($ids as $id) {                    if ($skip) {                        $skip = false;                    } else {                        $success = $success && delete_records('quiz_multichoice','id', $id->id);                    }                }            }        }    }    if ($success && $oldversion < 2005060300) {        //Search all the orphan categories (those whose course doesn't exist)        //and process them, deleting or moving them to site course - Bug 2459        //Set debug to false        $olddebug = $db->debug;        $db->debug = false;        //Iterate over all the quiz_categories records to get their course id        if ($courses = get_records_sql ("SELECT DISTINCT course as id, course                                         FROM {$CFG->prefix}quiz_categories")) {            //Iterate over courses            foreach ($courses as $course) {                //If the course doesn't exist, orphan category found!                //Process it with question_delete_course(). It will do all the hard work.                if (!record_exists('course', 'id', $course->id)) {                    require_once("$CFG->libdir/questionlib.php");                    $success = $success && question_delete_course($course);                }            }        }        //Reset rebug to its original state        $db->debug = $olddebug;    }    if ($success && $oldversion < 2005062600) {        $success = $success && modify_database ('', "            CREATE TABLE `prefix_quiz_essay` (                `id` int(10) unsigned NOT NULL auto_increment,                `question` int(10) unsigned NOT NULL default '0',                `answer` varchar(255) NOT NULL default '',                PRIMARY KEY  (`id`),                KEY `question` (`question`)           ) TYPE=MyISAM COMMENT='Options for essay questions'");            $success = $success && modify_database ('', "            CREATE TABLE `prefix_quiz_essay_states` (              `id` int(10) unsigned NOT NULL auto_increment,              `stateid` int(10) unsigned NOT NULL default '0',              `graded` tinyint(4) unsigned NOT NULL default '0',              `fraction` varchar(10) NOT NULL default '0.0',              `response` text NOT NULL,              PRIMARY KEY  (`id`)            ) TYPE=MyISAM COMMENT='essay question type specific state information'");    }    if ($success && $oldversion < 2005070202) {        // add new unique id to prepare the way for lesson module to have its own attempts table

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -