function qcreate_restore_mods($mod, $restore)
{
    global $CFG;
    $status = true;
    //Get record from backup_ids
    $data = backup_getid($restore->backup_unique_code, $mod->modtype, $mod->id);
    if ($data) {
        //Now get completed xmlized object
        $info = $data->info;
        //if necessary, write to restorelog and adjust date/time fields
        if ($restore->course_startdateoffset) {
            restore_log_date_changes('Qcreate', $restore, $info['MOD']['#'], array('TIMEOPEN', 'TIMECLOSE'));
        }
        //Now, build the QCREATE record structure
        $qcreate = new object();
        $qcreate->course = $restore->course_id;
        $qcreate->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
        $qcreate->grade = backup_todb($info['MOD']['#']['GRADE']['0']['#']);
        $qcreate->graderatio = backup_todb($info['MOD']['#']['GRADERATIO']['0']['#']);
        $qcreate->intro = backup_todb($info['MOD']['#']['INTRO']['0']['#']);
        $qcreate->introformat = backup_todb($info['MOD']['#']['INTROFORMAT']['0']['#']);
        $qcreate->allowed = backup_todb($info['MOD']['#']['ALLOWED']['0']['#']);
        $qcreate->totalrequired = backup_todb($info['MOD']['#']['TOTALREQUIRED']['0']['#']);
        $qcreate->studentqaccess = backup_todb($info['MOD']['#']['STUDENTQACCESS']['0']['#']);
        $qcreate->timesync = 0;
        $qcreate->timeopen = backup_todb($info['MOD']['#']['TIMEOPEN']['0']['#']);
        $qcreate->timeclose = backup_todb($info['MOD']['#']['TIMECLOSE']['0']['#']);
        $qcreate->timecreated = backup_todb($info['MOD']['#']['TIMECREATED']['0']['#']);
        $qcreate->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
        //We have to recode the grade field if it is <0 (scale)
        if ($qcreate->grade < 0) {
            $scale = backup_getid($restore->backup_unique_code, "scale", abs($qcreate->grade));
            if ($scale) {
                $qcreate->grade = -$scale->new_id;
            }
        }
        //The structure is equal to the db, so insert the qcreate
        $newid = insert_record("qcreate", $qcreate);
        //Do some output
        if (!defined('RESTORE_SILENTLY')) {
            echo "<li>" . get_string("modulename", "qcreate") . " \"" . format_string(stripslashes($qcreate->name), true) . "\"</li>";
        }
        backup_flush(300);
        if ($newid) {
            //We have the newid, update backup_ids
            backup_putid($restore->backup_unique_code, $mod->modtype, $mod->id, $newid);
            $status = qcreate_requireds_restore_mods($mod->id, $newid, $info, $restore) && $status;
            //Now check if want to restore user data and do it.
            if (restore_userdata_selected($restore, 'qcreate', $mod->id)) {
                //Restore qcreate_grades
                $status = qcreate_grades_restore_mods($mod->id, $newid, $info, $restore) && $status;
            }
        } else {
            $status = false;
        }
    } else {
        $status = false;
    }
    return $status;
}
Esempio n. 2
0
function webscheme_restore_mods($mod, $restore)
{
    global $CFG;
    $status = true;
    //Get record from backup_ids
    $data = backup_getid($restore->backup_unique_code, $mod->modtype, $mod->id);
    if ($data) {
        //Now get completed xmlized object
        $info = $data->info;
        // (STOLEN FROM CHOICE) if necessary, write to restorelog and adjust date/time fields
        if ($restore->course_startdateoffset) {
            restore_log_date_changes('Webscheme', $restore, $info['MOD']['#'], array('TIMEOPEN', 'TIMECLOSE'));
        }
        //traverse_xmlize($info);                                                                     //Debug
        //print_object ($GLOBALS['traverse_array']);                                                  //Debug
        //$GLOBALS['traverse_array']="";                                                              //Debug
        //Now, build the WEBSCHEME record structure
        $webscheme->course = $restore->course_id;
        $webscheme->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
        $webscheme->intro = backup_todb($info['MOD']['#']['INTRO']['0']['#']);
        $webscheme->introformat = backup_todb($info['MOD']['#']['INTROFORMAT']['0']['#']);
        $webscheme->timecreated = $info['MOD']['#']['TIMECREATED']['0']['#'];
        $webscheme->timemodified = $info['MOD']['#']['TIMEMODIFIED']['0']['#'];
        $ws_settings = $info['MOD']['#']['WS_SETTINGS']['0']['#'];
        $ws_settings = backup_todb(html_entity_decode($ws_settings));
        $webscheme->ws_settings = $ws_settings;
        $ws_events = $info['MOD']['#']['WS_EVENTS']['0']['#'];
        $ws_events = backup_todb(html_entity_decode($ws_events));
        $webscheme->ws_events = $ws_events;
        $ws_initexpr = $info['MOD']['#']['WS_INITEXPR']['0']['#'];
        $ws_initexpr = backup_todb(html_entity_decode($ws_initexpr));
        $webscheme->ws_initexpr = $ws_initexpr;
        $ws_loadurls = $info['MOD']['#']['WS_LOADURLS']['0']['#'];
        $ws_loadurls = backup_todb(html_entity_decode($ws_loadurls));
        $webscheme->ws_loadurls = $ws_loadurls;
        $ws_html = $info['MOD']['#']['WS_HTML']['0']['#'];
        $ws_html = backup_todb(html_entity_decode($ws_html));
        $webscheme->ws_html = $ws_html;
        //The structure is equal to the db, so insert the webscheme
        //  ah?  Do we need to addslashes or anything?
        $newid = insert_record("webscheme", $webscheme);
        //Do some output
        if (!defined('RESTORE_SILENTLY')) {
            echo "<li>" . get_string("modulename", "webscheme") . " \"" . format_string($webscheme->name, true) . "\"</li>";
        }
        backup_flush(300);
        if ($newid) {
            //We have the newid, update backup_ids
            backup_putid($restore->backup_unique_code, $mod->modtype, $mod->id, $newid);
        } else {
            $status = false;
        }
    } else {
        $status = false;
    }
    return $status;
}
Esempio n. 3
0
function wiki_restore_mods($mod, $restore)
{
    global $CFG, $DB;
    $status = true;
    //Get record from backup_ids
    $data = backup_getid($restore->backup_unique_code, $mod->modtype, $mod->id);
    if ($data) {
        //Now get completed xmlized object
        $info = $data->info;
        //if necessary, write to restorelog and adjust date/time fields
        if ($restore->course_startdateoffset) {
            restore_log_date_changes('Wiki', $restore, $info['MOD']['#'], array('TIMEMODIFIED'));
        }
        //traverse_xmlize($info);                                                                     //Debug
        //print_object ($GLOBALS['traverse_array']);                                                  //Debug
        //$GLOBALS['traverse_array']="";                                                              //Debug
        //Now, build the wiki record structure
        $wiki->course = $restore->course_id;
        $wiki->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
        $wiki->intro = backup_todb($info['MOD']['#']['SUMMARY']['0']['#']);
        $wiki->pagename = backup_todb($info['MOD']['#']['PAGENAME']['0']['#']);
        $wiki->wtype = backup_todb($info['MOD']['#']['WTYPE']['0']['#']);
        $wiki->ewikiprinttitle = backup_todb($info['MOD']['#']['EWIKIPRINTTITLE']['0']['#']);
        $wiki->htmlmode = backup_todb($info['MOD']['#']['HTMLMODE']['0']['#']);
        $wiki->ewikiacceptbinary = backup_todb($info['MOD']['#']['EWIKIACCEPTBINARY']['0']['#']);
        $wiki->disablecamelcase = backup_todb($info['MOD']['#']['DISABLECAMELCASE']['0']['#']);
        $wiki->setpageflags = backup_todb($info['MOD']['#']['SETPAGEFLAGS']['0']['#']);
        $wiki->strippages = backup_todb($info['MOD']['#']['STRIPPAGES']['0']['#']);
        $wiki->removepages = backup_todb($info['MOD']['#']['REMOVEPAGES']['0']['#']);
        $wiki->revertchanges = backup_todb($info['MOD']['#']['REVERTCHANGES']['0']['#']);
        $wiki->initialcontent = backup_todb($info['MOD']['#']['INITIALCONTENT']['0']['#']);
        $wiki->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
        //The structure is equal to the db, so insert the wiki
        $newid = $DB->insert_record("wiki", $wiki);
        //Do some output
        if (!defined('RESTORE_SILENTLY')) {
            echo "<li>" . get_string("modulename", "wiki") . " \"" . format_string($wiki->name, true) . "\"</li>";
        }
        backup_flush(300);
        if ($newid) {
            //We have the newid, update backup_ids
            backup_putid($restore->backup_unique_code, $mod->modtype, $mod->id, $newid);
            //Now check if want to restore user data and do it.
            if (restore_userdata_selected($restore, 'wiki', $mod->id)) {
                //Restore wiki_entries
                $status = wiki_entries_restore_mods($mod->id, $newid, $info, $restore);
            }
        } else {
            $status = false;
        }
    } else {
        $status = false;
    }
    return $status;
}
function journal_restore_mods($mod, $restore)
{
    global $CFG;
    $status = true;
    //Get record from backup_ids
    $data = backup_getid($restore->backup_unique_code, $mod->modtype, $mod->id);
    if ($data) {
        //Now get completed xmlized object
        $info = $data->info;
        //if necessary, write to restorelog and adjust date/time fields
        if ($restore->course_startdateoffset) {
            restore_log_date_changes('Journal', $restore, $info['MOD']['#'], array('TIMEMODIFIED'));
        }
        //traverse_xmlize($info);                                                                     //Debug
        //print_object ($GLOBALS['traverse_array']);                                                  //Debug
        //$GLOBALS['traverse_array']="";                                                              //Debug
        //Now, build the JOURNAL record structure
        $journal->course = $restore->course_id;
        $journal->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
        $journal->intro = backup_todb($info['MOD']['#']['INTRO']['0']['#']);
        $journal->introformat = backup_todb($info['MOD']['#']['INTROFORMAT']['0']['#']);
        $journal->days = backup_todb($info['MOD']['#']['DAYS']['0']['#']);
        $journal->assessed = backup_todb($info['MOD']['#']['ASSESSED']['0']['#']);
        $journal->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
        //We have to recode the assessed field if it is <0 (scale)
        if ($journal->assessed < 0) {
            $scale = backup_getid($restore->backup_unique_code, "scale", abs($journal->assessed));
            if ($scale) {
                $journal->assessed = -$scale->new_id;
            }
        }
        //The structure is equal to the db, so insert the journal
        $newid = insert_record("journal", $journal);
        //Do some output
        if (!defined('RESTORE_SILENTLY')) {
            echo "<li>" . get_string("modulename", "journal") . " \"" . format_string(stripslashes($journal->name), true) . "\"</li>";
        }
        backup_flush(300);
        if ($newid) {
            //We have the newid, update backup_ids
            backup_putid($restore->backup_unique_code, $mod->modtype, $mod->id, $newid);
            //Now check if want to restore user data and do it.
            if (restore_userdata_selected($restore, 'journal', $mod->id)) {
                //Restore journal_entries
                $status = journal_entries_restore_mods($mod->id, $newid, $info, $restore);
            }
        } else {
            $status = false;
        }
    } else {
        $status = false;
    }
    return $status;
}
function game_restore_mods($mod, $restore)
{
    global $CFG;
    $status = true;
    //Get record from backup_ids
    $data = backup_getid($restore->backup_unique_code, $mod->modtype, $mod->id);
    if ($data) {
        //Now get completed xmlized object
        $info = $data->info;
        //if necessary, write to restorelog and adjust date/time fields
        if ($restore->course_startdateoffset) {
            restore_log_date_changes('Game', $restore, $info['MOD']['#'], array('TIMEOPEN', 'TIMECLOSE'));
        }
        //Now, build the GAME record structure
        $game = new stdClass();
        $game->course = $restore->course_id;
        $mod_info = $info['MOD'];
        $fields = array('name', 'sourcemodule', 'quizid', 'glossaryid', 'glossarycategoryid', 'questioncategoryid', 'bookid', 'gameinputid', 'gamekind', 'param1', 'param2', 'param3', 'param4', 'param5', 'param6', 'param7', 'param8', 'timemodified', 'bottomtext', 'grademethod', 'grade', 'decimalpoints', 'popup', 'review', 'attempts', 'glossaryid2', 'glossarycategoryid2', 'language');
        game_restore_record($mod_info, $game, $fields);
        game_recode($restore->backup_unique_code, $game, 'quizid', 'quiz');
        game_recode($restore->backup_unique_code, $game, 'glossaryid', 'glossary');
        game_recode($restore->backup_unique_code, $game, 'glossarycategoryid', 'glossary_categories');
        game_recode($restore->backup_unique_code, $game, 'glossaryid2', 'glossary');
        game_recode($restore->backup_unique_code, $game, 'glossarycategoryid2', 'glossary_categories');
        game_restore_stamp($info, $restore, $map_question_categories, 'QUESTION_CATEGORIES', 'QUESTION_CATEGORY');
        game_restore_stamp($info, $restore, $map_questions, 'QUESTIONS', 'QUESTION');
        game_recode_questioncategoryid($game, $map_question_categories);
        game_recode($restore->backup_unique_code, $game, 'bookid', 'book');
        //The structure is equal to the db, so insert the game
        $newid = insert_record("game", $game);
        //Do some output
        if (!defined('RESTORE_SILENTLY')) {
            echo "<li>" . get_string("modulename", "game") . " \"" . format_string(stripslashes($game->name), true) . "\"</li>";
        }
        backup_flush(300);
        if ($newid) {
            //We have the newid, update backup_ids
            backup_putid($restore->backup_unique_code, $mod->modtype, $mod->id, $newid);
            //Now check if want to restore user data and do it.
            if (restore_userdata_selected($restore, 'game', $mod->id)) {
                $status = game_restore_grades($newid, $info, $restore);
                $status = game_restore_snakes_database($info, $restore);
                $status = game_restore_bookquiz_questions($newid, $info, $restore, $map_question_categories);
                //Restore game_attempts
                $status = game_attempts_restore_mods($newid, $info, $restore, $map_questions);
            }
        } else {
            $status = false;
        }
    } else {
        $status = false;
    }
    return $status;
}
Esempio n. 6
0
function blended_restore_mods($mod, $restore)
{
    global $CFG;
    $status = true;
    //Get record from backup_ids
    $data = backup_getid($restore->backup_unique_code, $mod->modtype, $mod->id);
    if ($data) {
        //Now get completed xmlized object
        $info = $data->info;
        //traverse_xmlize($info);                                                                     //Debug
        //print_object ($GLOBALS['traverse_array']);                                                  //Debug
        //$GLOBALS['traverse_array']="";                                                              //Debug
        // if necessary, write to restorelog and adjust date/time fields
        if ($restore->course_startdateoffset) {
            restore_log_date_changes('Blended', $restore, $info['MOD']['#'], array('TIMEOPEN', 'TIMECLOSE'));
        }
        //Now, build the BLENDED record structure
        $blended->course = $restore->course_id;
        $blended->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
        $blended->description = backup_todb($info['MOD']['#']['DESCRIPTION']['0']['#']);
        $blended->idmethod = backup_todb($info['MOD']['#']['IDMETHOD']['0']['#']);
        $blended->idtype = backup_todb($info['MOD']['#']['IDTYPE']['0']['#']);
        $blended->codebartype = backup_todb($info['MOD']['#']['CODEBARTYPE']['0']['#']);
        $blended->lengthuserinfo = backup_todb($info['MOD']['#']['LENGTHUSERINFO']['0']['#']);
        $blended->teammethod = backup_todb($info['MOD']['#']['TEAMMETHOD']['0']['#']);
        $blended->numteams = backup_todb($info['MOD']['#']['NUMTEAMS']['0']['#']);
        $blended->nummembers = backup_todb($info['MOD']['#']['MUMMEMBERS']['0']['#']);
        $blended->assignment = backup_todb($info['MOD']['#']['ASSIGNMENT']['0']['#']);
        $blended->randomkey = backup_todb($info['MOD']['#']['RANDOMKEY']['0']['#']);
        //The structure is equal to the db, so insert the chat
        $newid = insert_record("blended", $blended);
        //Do some output
        if (!defined('RESTORE_SILENTLY')) {
            echo "<li>" . get_string("modulename", "chat") . " \"" . format_string(stripslashes($blended->name), true) . "\"</li>";
        }
        backup_flush(300);
        if ($newid) {
            //We have the newid, update backup_ids
            backup_putid($restore->backup_unique_code, $mod->modtype, $mod->id, $newid);
            //Now check if want to restore user data and do it.
            if (restore_userdata_selected($restore, 'blended', $mod->id)) {
                //Restore chat_messages
                $status = blended_jobs_restore_mods($newid, $info, $restore);
            }
        } else {
            $status = false;
        }
    } else {
        $status = false;
    }
    return $status;
}
function nanogong_restore_mods($mod, $restore)
{
    global $CFG;
    $status = true;
    //Get record from backup_ids
    $data = backup_getid($restore->backup_unique_code, $mod->modtype, $mod->id);
    if ($data) {
        //Now get completed xmlized object
        $info = $data->info;
        //if necessary, write to restorelog and adjust date/time fields
        if ($restore->course_startdateoffset) {
            restore_log_date_changes('NanoGong', $restore, $info['MOD']['#'], array('TIMEDUE', 'TIMEAVAILABLE'));
        }
        //traverse_xmlize($info);                                                                     //Debug
        //print_object ($GLOBALS['traverse_array']);                                                  //Debug
        //$GLOBALS['traverse_array']="";                                                              //Debug
        // Now, build the NANOGONG record structure
        $nanogong->course = $restore->course_id;
        $nanogong->id = backup_todb($info['MOD']['#']['ID']['0']['#']);
        $nanogong->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
        $nanogong->message = backup_todb($info['MOD']['#']['MESSAGE']['0']['#']);
        $nanogong->color = backup_todb($info['MOD']['#']['COLOR']['0']['#']);
        $nanogong->maxduration = backup_todb($info['MOD']['#']['MAXDURATION']['0']['#']);
        $nanogong->maxmessages = backup_todb($info['MOD']['#']['MAXMESSAGES']['0']['#']);
        $nanogong->maxscore = backup_todb($info['MOD']['#']['MAXSCORE']['0']['#']);
        $nanogong->allowguestaccess = backup_todb($info['MOD']['#']['ALLOWGUESTACCESS']['0']['#']);
        $nanogong->timecreated = backup_todb($info['MOD']['#']['TIMECREATED']['0']['#']);
        $nanogong->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
        //The structure is equal to the db, so insert the nanogong
        $newid = insert_record("nanogong", $nanogong);
        //Do some output
        if (!defined('RESTORE_SILENTLY')) {
            echo "<li>" . get_string("modulename", "nanogong") . " \"" . format_string(stripslashes($nanogong->name), true) . "\"</li>";
        }
        backup_flush(300);
        if ($newid) {
            //We have the newid, update backup_ids
            backup_putid($restore->backup_unique_code, $mod->modtype, $mod->id, $newid);
            //Now check if want to restore user data and do it.
            if (restore_userdata_selected($restore, 'nanogong', $mod->id)) {
                //Restore nanogong messages
                $status = nanogong_messages_restore_mods($mod->id, $newid, $info, $restore);
            }
        } else {
            $status = false;
        }
    } else {
        $status = false;
    }
    return $status;
}
function checklist_restore_mods($mod, $restore)
{
    global $CFG, $db;
    $status = true;
    //Get record from backup_ids
    $data = backup_getid($restore->backup_unique_code, $mod->modtype, $mod->id);
    if ($data) {
        //Now get completed xmlized object
        $info = $data->info;
        //if necessary, write to restorelog and adjust date/time fields
        if ($restore->course_startdateoffset) {
            restore_log_date_changes('checklist', $restore, $info['MOD']['#'], array('TIMECREATED', 'TIMEMODIFIED'));
        }
        //traverse_xmlize($info);                                                                     //Debug
        //print_object ($GLOBALS['traverse_array']);                                                  //Debug
        //$GLOBALS['traverse_array']="";                                                              //Debug
        //Now, build the CHECKLIST record structure
        $checklist = new stdClass();
        $checklist->course = $restore->course_id;
        $checklist->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
        $checklist->intro = backup_todb($info['MOD']['#']['INTRO']['0']['#']);
        $checklist->introformat = backup_todb($info['MOD']['#']['INTROFORMAT']['0']['#']);
        $checklist->timecreated = backup_todb($info['MOD']['#']['TIMECREATED']['0']['#']);
        $checklist->timecreated += $restore->course_startdateoffset;
        $checklist->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
        $checklist->timemodified += $restore->course_startdateoffset;
        $checklist->useritemsallowed = backup_todb($info['MOD']['#']['USERITEMSALLOWED']['0']['#']);
        $checklist->teacheredit = backup_todb($info['MOD']['#']['TEACHEREDIT']['0']['#']);
        $checklist->theme = backup_todb($info['MOD']['#']['THEME']['0']['#']);
        $checklist->duedatesoncalendar = backup_todb_chk_optional_field($info['MOD'], 'DUEDATESONCALENDAR', false);
        $checklist->teachercomments = backup_todb_chk_optional_field($info['MOD'], 'TEACHERCOMMENTS', false);
        $newid = insert_record('checklist', $checklist);
        //Do some output
        if (!defined('RESTORE_SILENTLY')) {
            echo "<li>" . get_string('modulename', 'checklist') . " \"" . format_string(stripslashes($checklist->name), true) . "\"</li>";
        }
        backup_flush(300);
        if ($newid) {
            //We have the newid, update backup_ids
            backup_putid($restore->backup_unique_code, $mod->modtype, $mod->id, $newid);
            $checklist->id = $newid;
            $restore_user = restore_userdata_selected($restore, 'checklist', $mod->id);
            $status = checklist_items_restore($newid, $info, $restore, $restore_user);
        } else {
            $status = false;
        }
    } else {
        $status = false;
    }
    return $status;
}
Esempio n. 9
0
function textanalysis_restore_mods($mod, $restore)
{
    global $CFG, $oldidarray;
    $status = true;
    //Get record from backup_ids
    $data = backup_getid($restore->backup_unique_code, $mod->modtype, $mod->id);
    if ($data) {
        //Now get completed xmlized object
        $info = $data->info;
        //traverse_xmlize($info);                                                                     //Debug
        //print_object ($GLOBALS['traverse_array']);                                                  //Debug
        //$GLOBALS['traverse_array']="";                                                              //Debug
        // if necessary, write to restorelog and adjust date/time fields
        if ($restore->course_startdateoffset) {
            restore_log_date_changes('textanalysis', $restore, $info['MOD']['#'], array('TEXTANALYSISTIME'));
        }
        //Now, build the textanalysis record structure
        $textanalysis->course = $restore->course_id;
        $textanalysis->teacher = backup_todb($info['MOD']['#']['TEACHER']['0']['#']);
        $textanalysis->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
        $textanalysis->intro = backup_todb($info['MOD']['#']['INTRO']['0']['#']);
        $textanalysis->type = backup_todb($info['MOD']['#']['TYPE']['0']['#']);
        $textanalysis->time = backup_todb($info['MOD']['#']['TIME']['0']['#']);
        $user = backup_getid($restore->backup_unique_code, "user", $textanalysis->teacher);
        if ($user) {
            $textanalysis->teacher = $user->new_id;
        }
        //The structure is equal to the db, so insert the textanalysis
        $newid = insert_record("textanalysis", $textanalysis);
        //Do some output
        //if (!defined('RESTORE_SILENTLY')) {
        //    echo "<li>".get_string("modulename","textanalysis")." \"".format_string(stripslashes($textanalysis->name),true)."\"</li>";
        //}
        //backup_flush(300);
        if ($newid) {
            //We have the newid, update backup_ids
            backup_putid($restore->backup_unique_code, $mod->modtype, $mod->id, $newid);
            //Now check if want to restore user data and do it.
            if (restore_userdata_selected($restore, 'textanalysis', $mod->id)) {
                //Restore textanalysis_messages
            }
        } else {
            $status = false;
        }
    } else {
        $status = false;
    }
    return $status;
}
Esempio n. 10
0
function realtimequiz_restore_mods($mod, $restore)
{
    global $CFG, $db;
    $status = true;
    //Get record from backup_ids
    $data = backup_getid($restore->backup_unique_code, $mod->modtype, $mod->id);
    if ($data) {
        //Now get completed xmlized object
        $info = $data->info;
        //if necessary, write to restorelog and adjust date/time fields
        if ($restore->course_startdateoffset) {
            restore_log_date_changes('Realtimequiz', $restore, $info['MOD']['#'], array('ASSESSTIMESTART', 'ASSESSTIMEFINISH'));
        }
        //traverse_xmlize($info);                                                                     //Debug
        //print_object ($GLOBALS['traverse_array']);                                                  //Debug
        //$GLOBALS['traverse_array']="";                                                              //Debug
        //Now, build the REALTIMEQUIZ record structure
        $quiz->course = $restore->course_id;
        $quiz->type = backup_todb($info['MOD']['#']['TYPE']['0']['#']);
        $quiz->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
        $quiz->questiontime = backup_todb($info['MOD']['#']['QUESTIONTIME']['0']['#']);
        $newid = insert_record("realtimequiz", $quiz);
        //Do some output
        if (!defined('RESTORE_SILENTLY')) {
            echo "<li>" . get_string("modulename", "realtimequiz") . " \"" . format_string(stripslashes($quiz->name), true) . "\"</li>";
        }
        backup_flush(300);
        if ($newid) {
            //We have the newid, update backup_ids
            backup_putid($restore->backup_unique_code, $mod->modtype, $mod->id, $newid);
            $quiz->id = $newid;
            $restore_user = false;
            //Now check if want to restore user data and do it.
            if (restore_userdata_selected($restore, 'realtimequiz', $mod->id)) {
                $status = realtimequiz_sessions_restore($newid, $info, $restore);
                $restore_user = true;
            }
            // Restore the questions and answers (and any submissions)
            if ($status) {
                $status = realtimequiz_questions_restore($newid, $info, $restore, $restore_user);
            }
        } else {
            $status = false;
        }
    } else {
        $status = false;
    }
    return $status;
}
Esempio n. 11
0
function chat_restore_mods($mod, $restore)
{
    global $CFG;
    $status = true;
    //Get record from backup_ids
    $data = backup_getid($restore->backup_unique_code, $mod->modtype, $mod->id);
    if ($data) {
        //Now get completed xmlized object
        $info = $data->info;
        //traverse_xmlize($info);                                                                     //Debug
        //print_object ($GLOBALS['traverse_array']);                                                  //Debug
        //$GLOBALS['traverse_array']="";                                                              //Debug
        // if necessary, write to restorelog and adjust date/time fields
        if ($restore->course_startdateoffset) {
            restore_log_date_changes('Chat', $restore, $info['MOD']['#'], array('CHATTIME'));
        }
        //Now, build the CHAT record structure
        $chat->course = $restore->course_id;
        $chat->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
        $chat->intro = backup_todb($info['MOD']['#']['INTRO']['0']['#']);
        $chat->keepdays = backup_todb($info['MOD']['#']['KEEPDAYS']['0']['#']);
        $chat->studentlogs = backup_todb($info['MOD']['#']['STUDENTLOGS']['0']['#']);
        $chat->schedule = backup_todb($info['MOD']['#']['SCHEDULE']['0']['#']);
        $chat->chattime = backup_todb($info['MOD']['#']['CHATTIME']['0']['#']);
        $chat->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
        //The structure is equal to the db, so insert the chat
        $newid = insert_record("chat", $chat);
        //Do some output
        if (!defined('RESTORE_SILENTLY')) {
            echo "<li>" . get_string("modulename", "chat") . " \"" . format_string(stripslashes($chat->name), true) . "\"</li>";
        }
        backup_flush(300);
        if ($newid) {
            //We have the newid, update backup_ids
            backup_putid($restore->backup_unique_code, $mod->modtype, $mod->id, $newid);
            //Now check if want to restore user data and do it.
            if (restore_userdata_selected($restore, 'chat', $mod->id)) {
                //Restore chat_messages
                $status = chat_messages_restore_mods($mod->id, $newid, $info, $restore);
            }
        } else {
            $status = false;
        }
    } else {
        $status = false;
    }
    return $status;
}
/**
 * Restore the module
 *
 * @param object $mod Module to restore from XML
 * @param object $restore Restore process settings
 * @return boolean True if success, False if failure
 */
function stampcoll_restore_mods($mod, $restore)
{
    $status = true;
    //Get record from backup_ids
    $data = backup_getid($restore->backup_unique_code, $mod->modtype, $mod->id);
    if ($data) {
        //get completed xmlized object
        $info = $data->info;
        //if necessary, write to restorelog and adjust date/time fields
        if (!empty($restore->course_startdateoffset)) {
            restore_log_date_changes('Stamp collection', $restore, $info['MOD']['#'], array('TIMEMODIFIED'));
        }
        //traverse_xmlize($info);                                                                    //Debug
        //print_object($GLOBALS['traverse_array']);                                                  //Debug
        //$GLOBALS['traverse_array'] = '';                                                           //Debug
        //build the record structure
        $stampcoll = new stdClass();
        $stampcoll->course = $restore->course_id;
        $stampcoll->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
        $stampcoll->text = backup_todb($info['MOD']['#']['TEXT']['0']['#']);
        $stampcoll->format = backup_todb($info['MOD']['#']['FORMAT']['0']['#']);
        $stampcoll->image = backup_todb($info['MOD']['#']['IMAGE']['0']['#']);
        $stampcoll->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
        $stampcoll->displayzero = backup_todb($info['MOD']['#']['DISPLAYZERO']['0']['#']);
        // following was added in Moodle 1.9. If it is not present, consider stampcoll as anonymous
        // (we did not keep the giver id pre 1.9)
        if (isset($info['MOD']['#']['ANONYMOUS']['0']['#'])) {
            $stampcoll->anonymous = backup_todb($info['MOD']['#']['ANONYMOUS']['0']['#']);
        } else {
            $stampcoll->anonymous = 1;
        }
        //following two fields get dropped in Moodle 1.9. Therefore they might or not be there
        //depending on whether we are restoring a 1.8 or 1.9 backup
        if (isset($info['MOD']['#']['PUBLISH']['0']['#'])) {
            $stampcoll->publish = backup_todb($info['MOD']['#']['PUBLISH']['0']['#']);
        }
        if (isset($info['MOD']['#']['TEACHERCANCOLLECT']['0']['#'])) {
            $stampcoll->teachercancollect = backup_todb($info['MOD']['#']['TEACHERCANCOLLECT']['0']['#']);
        }
        //the structure is equal to the db now, so insert the stampcoll
        $newid = insert_record('stampcoll', $stampcoll);
        //do some output
        if (!defined('RESTORE_SILENTLY')) {
            echo '<li>' . get_string('modulename', 'stampcoll') . ' "' . format_string(stripslashes($stampcoll->name), true) . '"</li>';
        }
        backup_flush(300);
        if ($newid) {
            //we have the newid, update backup_ids
            backup_putid($restore->backup_unique_code, $mod->modtype, $mod->id, $newid);
            //check if user wants to restore user data and do it
            if (restore_userdata_selected($restore, 'stampcoll', $mod->id)) {
                $status = stampcoll_restore_collected_stamps($mod->id, $newid, $info, $restore);
            }
            // if the backup was made in 1.8, we need to convert PUBLISH and TEACHERCANCOLLECT into
            // local role overrides
            if (isset($stampcoll->publish) && isset($stampcoll->teachercancollect)) {
                $cmid = $restore->mods['stampcoll']->instances[$mod->id]->restored_as_course_module;
                $context = get_context_instance(CONTEXT_MODULE, $cmid);
                if (!($editingteacherroles = get_roles_with_capability('moodle/legacy:editingteacher', CAP_ALLOW))) {
                    notice('Default editing teacher role was not found. Roles and permissions ' . 'for the stampcoll module will have to be manually set.');
                }
                if (!($teacherroles = get_roles_with_capability('moodle/legacy:teacher', CAP_ALLOW))) {
                    notice('Default teacher role was not found. Roles and permissions ' . 'for the stampcoll module will have to be manually set.');
                }
                if (!($studentroles = get_roles_with_capability('moodle/legacy:student', CAP_ALLOW))) {
                    notice('Default student role was not found. Roles and permissions ' . 'for the stampcoll module will have to be manually set.');
                }
                // collection with publish set to STAMPCOLL_PUBLISH_NONE
                if ($stampcoll->publish == 0) {
                    // prevent students from viewing own stamps
                    foreach ($studentroles as $studentrole) {
                        assign_capability('mod/stampcoll:viewownstamps', CAP_PREVENT, $studentrole->id, $context->id);
                    }
                }
                // collection with publish set to STAMPCOLL_PUBLISH_ALL
                if ($stampcoll->publish == 2) {
                    // allow students to view others' stamps
                    foreach ($studentroles as $studentrole) {
                        assign_capability('mod/stampcoll:viewotherstamps', CAP_ALLOW, $studentrole->id, $context->id);
                    }
                }
                // collection which allows teachers to collect stamps
                if ($stampcoll->teachercancollect == 1) {
                    foreach ($editingteacherroles as $teacherrole) {
                        assign_capability('mod/stampcoll:collectstamps', CAP_ALLOW, $teacherrole->id, $context->id);
                    }
                    foreach ($teacherroles as $teacherrole) {
                        assign_capability('mod/stampcoll:collectstamps', CAP_ALLOW, $teacherrole->id, $context->id);
                    }
                }
            }
        } else {
            // insert_record() failed
            $status = false;
        }
    } else {
        // backup_getid() failed
        $status = false;
    }
    return $status;
}
Esempio n. 13
0
function quiz_restore_mods($mod, $restore)
{
    global $CFG;
    $status = true;
    //Hook to call Moodle < 1.5 Quiz Restore
    if ($restore->backup_version < 2005043000) {
        include_once "restorelibpre15.php";
        return quiz_restore_pre15_mods($mod, $restore);
    }
    //Get record from backup_ids
    $data = backup_getid($restore->backup_unique_code, $mod->modtype, $mod->id);
    if ($data) {
        //Now get completed xmlized object
        $info = $data->info;
        //if necessary, write to restorelog and adjust date/time fields
        if ($restore->course_startdateoffset) {
            restore_log_date_changes('Quiz', $restore, $info['MOD']['#'], array('TIMEOPEN', 'TIMECLOSE'));
        }
        //traverse_xmlize($info);                                                                     //Debug
        //print_object ($GLOBALS['traverse_array']);                                                  //Debug
        //$GLOBALS['traverse_array']="";                                                              //Debug
        //Now, build the QUIZ record structure
        $quiz = new stdClass();
        $quiz->course = $restore->course_id;
        $quiz->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
        $quiz->intro = backup_todb($info['MOD']['#']['INTRO']['0']['#']);
        $quiz->timeopen = backup_todb($info['MOD']['#']['TIMEOPEN']['0']['#']);
        $quiz->timeclose = backup_todb($info['MOD']['#']['TIMECLOSE']['0']['#']);
        $quiz->optionflags = backup_todb($info['MOD']['#']['OPTIONFLAGS']['0']['#']);
        $quiz->penaltyscheme = backup_todb($info['MOD']['#']['PENALTYSCHEME']['0']['#']);
        $quiz->attempts = backup_todb($info['MOD']['#']['ATTEMPTS_NUMBER']['0']['#']);
        $quiz->attemptonlast = backup_todb($info['MOD']['#']['ATTEMPTONLAST']['0']['#']);
        $quiz->grademethod = backup_todb($info['MOD']['#']['GRADEMETHOD']['0']['#']);
        $quiz->decimalpoints = backup_todb($info['MOD']['#']['DECIMALPOINTS']['0']['#']);
        $quiz->review = backup_todb($info['MOD']['#']['REVIEW']['0']['#']);
        $quiz->questionsperpage = backup_todb($info['MOD']['#']['QUESTIONSPERPAGE']['0']['#']);
        $quiz->shufflequestions = backup_todb($info['MOD']['#']['SHUFFLEQUESTIONS']['0']['#']);
        $quiz->shuffleanswers = backup_todb($info['MOD']['#']['SHUFFLEANSWERS']['0']['#']);
        $quiz->questions = backup_todb($info['MOD']['#']['QUESTIONS']['0']['#']);
        $quiz->sumgrades = backup_todb($info['MOD']['#']['SUMGRADES']['0']['#']);
        $quiz->grade = backup_todb($info['MOD']['#']['GRADE']['0']['#']);
        $quiz->timecreated = backup_todb($info['MOD']['#']['TIMECREATED']['0']['#']);
        $quiz->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
        $quiz->timelimit = backup_todb($info['MOD']['#']['TIMELIMIT']['0']['#']);
        $quiz->password = backup_todb($info['MOD']['#']['PASSWORD']['0']['#']);
        $quiz->subnet = backup_todb($info['MOD']['#']['SUBNET']['0']['#']);
        $quiz->popup = backup_todb($info['MOD']['#']['POPUP']['0']['#']);
        $quiz->delay1 = isset($info['MOD']['#']['DELAY1']['0']['#']) ? backup_todb($info['MOD']['#']['DELAY1']['0']['#']) : '';
        $quiz->delay2 = isset($info['MOD']['#']['DELAY2']['0']['#']) ? backup_todb($info['MOD']['#']['DELAY2']['0']['#']) : '';
        //We have to recode the questions field (a list of questions id and pagebreaks)
        $quiz->questions = quiz_recode_layout($quiz->questions, $restore);
        //The structure is equal to the db, so insert the quiz
        $newid = insert_record("quiz", $quiz);
        //Do some output
        if (!defined('RESTORE_SILENTLY')) {
            echo "<li>" . get_string("modulename", "quiz") . " \"" . format_string(stripslashes($quiz->name), true) . "\"</li>";
        }
        backup_flush(300);
        if ($newid) {
            //We have the newid, update backup_ids
            backup_putid($restore->backup_unique_code, $mod->modtype, $mod->id, $newid);
            //We have to restore the question_instances now (course level table)
            $status = quiz_question_instances_restore_mods($newid, $info, $restore);
            //We have to restore the feedback now (course level table)
            $status = quiz_feedback_restore_mods($newid, $info, $restore, $quiz);
            //We have to restore the question_versions now (course level table)
            $status = quiz_question_versions_restore_mods($newid, $info, $restore);
            //Now check if want to restore user data and do it.
            if (restore_userdata_selected($restore, 'quiz', $mod->id)) {
                //Restore quiz_attempts
                $status = quiz_attempts_restore_mods($newid, $info, $restore);
                if ($status) {
                    //Restore quiz_grades
                    $status = quiz_grades_restore_mods($newid, $info, $restore);
                }
            }
        } else {
            $status = false;
        }
    } else {
        $status = false;
    }
    return $status;
}
function quiz_restore_pre15_mods($mod, $restore)
{
    global $CFG;
    $status = true;
    //Get record from backup_ids
    $data = backup_getid($restore->backup_unique_code, $mod->modtype, $mod->id);
    if ($data) {
        //Now get completed xmlized object
        $info = $data->info;
        //if necessary, write to restorelog and adjust date/time fields
        if ($restore->course_startdateoffset) {
            restore_log_date_changes('Quiz', $restore, $info['MOD']['#'], array('TIMEOPEN', 'TIMECLOSE'));
        }
        //traverse_xmlize($info);                                                                     //Debug
        //print_object ($GLOBALS['traverse_array']);                                                  //Debug
        //$GLOBALS['traverse_array']="";                                                              //Debug
        //Now, build the QUIZ record structure
        $quiz->course = $restore->course_id;
        $quiz->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
        $quiz->intro = backup_todb($info['MOD']['#']['INTRO']['0']['#']);
        $quiz->timeopen = backup_todb($info['MOD']['#']['TIMEOPEN']['0']['#']);
        $quiz->timeclose = backup_todb($info['MOD']['#']['TIMECLOSE']['0']['#']);
        $quiz->attempts = backup_todb($info['MOD']['#']['ATTEMPTS_NUMBER']['0']['#']);
        $quiz->attemptonlast = backup_todb($info['MOD']['#']['ATTEMPTONLAST']['0']['#']);
        $quiz->feedback = backup_todb($info['MOD']['#']['FEEDBACK']['0']['#']);
        $quiz->correctanswers = backup_todb($info['MOD']['#']['CORRECTANSWERS']['0']['#']);
        $quiz->grademethod = backup_todb($info['MOD']['#']['GRADEMETHOD']['0']['#']);
        if (isset($info['MOD']['#']['DECIMALPOINTS']['0']['#'])) {
            //Only if it's set, to apply DB default else.
            $quiz->decimalpoints = backup_todb($info['MOD']['#']['DECIMALPOINTS']['0']['#']);
        }
        $quiz->review = backup_todb($info['MOD']['#']['REVIEW']['0']['#']);
        $quiz->questionsperpage = backup_todb($info['MOD']['#']['QUESTIONSPERPAGE']['0']['#']);
        $quiz->shufflequestions = backup_todb($info['MOD']['#']['SHUFFLEQUESTIONS']['0']['#']);
        $quiz->shuffleanswers = backup_todb($info['MOD']['#']['SHUFFLEANSWERS']['0']['#']);
        $quiz->questions = backup_todb($info['MOD']['#']['QUESTIONS']['0']['#']);
        $quiz->sumgrades = backup_todb($info['MOD']['#']['SUMGRADES']['0']['#']);
        $quiz->grade = backup_todb($info['MOD']['#']['GRADE']['0']['#']);
        $quiz->timecreated = backup_todb($info['MOD']['#']['TIMECREATED']['0']['#']);
        $quiz->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
        $quiz->timelimit = backup_todb($info['MOD']['#']['TIMELIMIT']['0']['#']);
        $quiz->password = backup_todb($info['MOD']['#']['PASSWORD']['0']['#']);
        $quiz->subnet = backup_todb($info['MOD']['#']['SUBNET']['0']['#']);
        $quiz->popup = backup_todb($info['MOD']['#']['POPUP']['0']['#']);
        //We have to recode the questions field (a list of questions id)
        $newquestions = array();
        if ($questionsarr = explode(",", $quiz->questions)) {
            foreach ($questionsarr as $key => $value) {
                if ($question = backup_getid($restore->backup_unique_code, "question", $value)) {
                    $newquestions[] = $question->new_id;
                }
            }
        }
        $quiz->questions = implode(",", $newquestions);
        //Recalculate the questions field to include page breaks if necessary
        $quiz->questions = quiz_repaginate($quiz->questions, $quiz->questionsperpage);
        //Calculate the new review field contents (logic extracted from upgrade)
        $review = QUIZ_REVIEW_IMMEDIATELY & QUIZ_REVIEW_RESPONSES + QUIZ_REVIEW_SCORES;
        if ($quiz->feedback) {
            $review += QUIZ_REVIEW_IMMEDIATELY & QUIZ_REVIEW_FEEDBACK;
        }
        if ($quiz->correctanswers) {
            $review += QUIZ_REVIEW_IMMEDIATELY & QUIZ_REVIEW_ANSWERS;
        }
        if ($quiz->review & 1) {
            $review += QUIZ_REVIEW_CLOSED;
        }
        if ($quiz->review & 2) {
            $review += QUIZ_REVIEW_OPEN;
        }
        $quiz->review = $review;
        //The structure is equal to the db, so insert the quiz
        $newid = insert_record("quiz", $quiz);
        //Do some output
        if (!defined('RESTORE_SILENTLY')) {
            echo "<li>" . get_string("modulename", "quiz") . " \"" . format_string(stripslashes($quiz->name), true) . "\"</li>";
        }
        backup_flush(300);
        if ($newid) {
            //We have the newid, update backup_ids
            backup_putid($restore->backup_unique_code, $mod->modtype, $mod->id, $newid);
            //We have to restore the quiz_question_instances now (old quiz_question_grades, course level)
            $status = quiz_question_instances_restore_pre15_mods($newid, $info, $restore);
            //We have to restore the question_versions now (course level table)
            $status = quiz_question_versions_restore_pre15_mods($newid, $info, $restore);
            //Now check if want to restore user data and do it.
            if (restore_userdata_selected($restore, 'quiz', $mod->id)) {
                //Restore quiz_attempts
                $status = quiz_attempts_restore_pre15_mods($newid, $info, $restore, $quiz->questions);
                if ($status) {
                    //Restore quiz_grades
                    $status = quiz_grades_restore_pre15_mods($newid, $info, $restore);
                }
            }
        } else {
            $status = false;
        }
    } else {
        $status = false;
    }
    return $status;
}
Esempio n. 15
0
function forum_restore_mods($mod, $restore)
{
    global $CFG, $DB;
    $status = true;
    //Get record from backup_ids
    $data = backup_getid($restore->backup_unique_code, $mod->modtype, $mod->id);
    if ($data) {
        //Now get completed xmlized object
        $info = $data->info;
        //if necessary, write to restorelog and adjust date/time fields
        if ($restore->course_startdateoffset) {
            restore_log_date_changes('Forum', $restore, $info['MOD']['#'], array('ASSESSTIMESTART', 'ASSESSTIMEFINISH'));
        }
        //traverse_xmlize($info);                                                                     //Debug
        //print_object ($GLOBALS['traverse_array']);                                                  //Debug
        //$GLOBALS['traverse_array']="";                                                              //Debug
        //Now, build the FORUM record structure
        $forum->course = $restore->course_id;
        $forum->type = backup_todb($info['MOD']['#']['TYPE']['0']['#']);
        $forum->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
        $forum->intro = backup_todb($info['MOD']['#']['INTRO']['0']['#']);
        // These get dropped in Moodle 1.7 when the new Roles System gets
        // set up. Therefore they might or not be there depending on whether
        // we are restoring a 1.6+ forum or a 1.7 or later forum backup.
        if (isset($info['MOD']['#']['OPEN']['0']['#'])) {
            $forum->open = backup_todb($info['MOD']['#']['OPEN']['0']['#']);
        }
        if (isset($info['MOD']['#']['ASSESSPUBLIC']['0']['#'])) {
            $forum->assesspublic = backup_todb($info['MOD']['#']['ASSESSPUBLIC']['0']['#']);
        }
        $forum->assessed = backup_todb($info['MOD']['#']['ASSESSED']['0']['#']);
        $forum->assesstimestart = backup_todb($info['MOD']['#']['ASSESSTIMESTART']['0']['#']);
        $forum->assesstimefinish = backup_todb($info['MOD']['#']['ASSESSTIMEFINISH']['0']['#']);
        $forum->maxbytes = backup_todb($info['MOD']['#']['MAXBYTES']['0']['#']);
        $forum->scale = backup_todb($info['MOD']['#']['SCALE']['0']['#']);
        $forum->forcesubscribe = backup_todb($info['MOD']['#']['FORCESUBSCRIBE']['0']['#']);
        $forum->trackingtype = backup_todb($info['MOD']['#']['TRACKINGTYPE']['0']['#']);
        $forum->rsstype = backup_todb($info['MOD']['#']['RSSTYPE']['0']['#']);
        $forum->rssarticles = backup_todb($info['MOD']['#']['RSSARTICLES']['0']['#']);
        $forum->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
        $forum->warnafter = isset($info['MOD']['#']['WARNAFTER']['0']['#']) ? backup_todb($info['MOD']['#']['WARNAFTER']['0']['#']) : '';
        $forum->blockafter = isset($info['MOD']['#']['BLOCKAFTER']['0']['#']) ? backup_todb($info['MOD']['#']['BLOCKAFTER']['0']['#']) : '';
        $forum->blockperiod = isset($info['MOD']['#']['BLOCKPERIOD']['0']['#']) ? backup_todb($info['MOD']['#']['BLOCKPERIOD']['0']['#']) : '';
        $forum->completiondiscussions = isset($info['MOD']['#']['COMPLETIONDISCUSSIONS']['0']['#']) ? backup_todb($info['MOD']['#']['COMPLETIONDISCUSSIONS']['0']['#']) : 0;
        $forum->completionreplies = isset($info['MOD']['#']['COMPLETIONREPLIES']['0']['#']) ? backup_todb($info['MOD']['#']['COMPLETIONREPLIES']['0']['#']) : 0;
        $forum->completionposts = isset($info['MOD']['#']['COMPLETIONPOSTS']['0']['#']) ? backup_todb($info['MOD']['#']['COMPLETIONPOSTS']['0']['#']) : 0;
        //We have to recode the scale field if it's <0 (positive is a grade, not a scale)
        if ($forum->scale < 0) {
            $scale = backup_getid($restore->backup_unique_code, "scale", abs($forum->scale));
            if ($scale) {
                $forum->scale = -$scale->new_id;
            }
        }
        $newid = $DB->insert_record("forum", $forum);
        //Do some output
        if (!defined('RESTORE_SILENTLY')) {
            echo "<li>" . get_string("modulename", "forum") . " \"" . format_string($forum->name, true) . "\"</li>";
        }
        backup_flush(300);
        if ($newid) {
            //We have the newid, update backup_ids
            backup_putid($restore->backup_unique_code, $mod->modtype, $mod->id, $newid);
            $forum->id = $newid;
            //Now check if want to restore user data and do it.
            if (restore_userdata_selected($restore, 'forum', $mod->id)) {
                //Restore forum_subscriptions
                $status = forum_subscriptions_restore_mods($newid, $info, $restore);
                if ($status) {
                    //Restore forum_discussions
                    $status = forum_discussions_restore_mods($newid, $info, $restore);
                }
                if ($status) {
                    //Restore forum_read
                    $status = forum_read_restore_mods($newid, $info, $restore);
                }
            }
            // If forum type is single, just recreate the initial discussion/post automatically
            // if it hasn't been created still (because no user data was selected on backup or
            // restore.
            if ($forum->type == 'single' && !$DB->record_exists('forum_discussions', array('forum' => $newid))) {
                //Load forum/lib.php
                require_once $CFG->dirroot . '/mod/forum/lib.php';
                // Calculate the default format
                if (can_use_html_editor()) {
                    $defaultformat = FORMAT_HTML;
                } else {
                    $defaultformat = FORMAT_MOODLE;
                }
                //Create discussion/post data
                $sd = new stdClass();
                $sd->course = $forum->course;
                $sd->forum = $newid;
                $sd->name = $forum->name;
                $sd->intro = $forum->intro;
                $sd->assessed = $forum->assessed;
                $sd->messageformat = $defaultformat;
                $sd->mailnow = false;
                //Insert dicussion/post data
                $sdid = forum_add_discussion($sd, $sd->intro, $forum);
                //Now, mark the initial post of the discussion as mailed!
                if ($sdid) {
                    $DB->set_field('forum_posts', 'mailed', '1', array('discussion' => $sdid));
                }
            }
        } else {
            $status = false;
        }
        // If the backup contained $forum->open and $forum->assesspublic,
        // we need to convert the forum to use Roles. It means the backup
        // was made pre Moodle 1.7.
        if (isset($forum->open) && isset($forum->assesspublic)) {
            $forummod = $DB->get_record('modules', array('name' => 'forum'));
            if (!($teacherroles = get_roles_with_capability('moodle/legacy:teacher', CAP_ALLOW))) {
                notice('Default teacher role was not found. Roles and permissions ' . 'for all your forums will have to be manually set.');
            }
            if (!($studentroles = get_roles_with_capability('moodle/legacy:student', CAP_ALLOW))) {
                notice('Default student role was not found. Roles and permissions ' . 'for all your forums will have to be manually set.');
            }
            if (!($guestroles = get_roles_with_capability('moodle/legacy:guest', CAP_ALLOW))) {
                notice('Default guest role was not found. Roles and permissions ' . 'for teacher forums will have to be manually set.');
            }
            require_once $CFG->dirroot . '/mod/forum/lib.php';
            forum_convert_to_roles($forum, $forummod->id, $teacherroles, $studentroles, $guestroles, $restore->mods['forum']->instances[$mod->id]->restored_as_course_module);
        }
    } else {
        $status = false;
    }
    return $status;
}
Esempio n. 16
0
function glossary_restore_mods($mod, $restore)
{
    global $CFG, $DB;
    $status = true;
    //Get record from backup_ids
    $data = backup_getid($restore->backup_unique_code, $mod->modtype, $mod->id);
    if ($data) {
        //Now get completed xmlized object
        $info = $data->info;
        // if necessary, write to restorelog and adjust date/time fields
        if ($restore->course_startdateoffset) {
            restore_log_date_changes('Glossary', $restore, $info['MOD']['#'], array('ASSESSTIMESTART', 'ASSESSTIMEFINISH'));
        }
        //traverse_xmlize($info);                                                                     //Debug
        //print_object ($GLOBALS['traverse_array']);                                                  //Debug
        //$GLOBALS['traverse_array']="";                                                              //Debug
        //Now, build the glossary record structure
        $glossary->course = $restore->course_id;
        $glossary->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
        $glossary->intro = backup_todb($info['MOD']['#']['INTRO']['0']['#']);
        $glossary->allowduplicatedentries = backup_todb($info['MOD']['#']['ALLOWDUPLICATEDENTRIES']['0']['#']);
        $glossary->displayformat = backup_todb($info['MOD']['#']['DISPLAYFORMAT']['0']['#']);
        $glossary->mainglossary = backup_todb($info['MOD']['#']['MAINGLOSSARY']['0']['#']);
        $glossary->showspecial = backup_todb($info['MOD']['#']['SHOWSPECIAL']['0']['#']);
        $glossary->showalphabet = backup_todb($info['MOD']['#']['SHOWALPHABET']['0']['#']);
        $glossary->showall = backup_todb($info['MOD']['#']['SHOWALL']['0']['#']);
        $glossary->allowcomments = backup_todb($info['MOD']['#']['ALLOWCOMMENTS']['0']['#']);
        $glossary->allowprintview = backup_todb($info['MOD']['#']['ALLOWPRINTVIEW']['0']['#']);
        $glossary->usedynalink = backup_todb($info['MOD']['#']['USEDYNALINK']['0']['#']);
        $glossary->defaultapproval = backup_todb($info['MOD']['#']['DEFAULTAPPROVAL']['0']['#']);
        $glossary->globalglossary = backup_todb($info['MOD']['#']['GLOBALGLOSSARY']['0']['#']);
        $glossary->entbypage = backup_todb($info['MOD']['#']['ENTBYPAGE']['0']['#']);
        $glossary->editalways = backup_todb($info['MOD']['#']['EDITALWAYS']['0']['#']);
        $glossary->rsstype = backup_todb($info['MOD']['#']['RSSTYPE']['0']['#']);
        $glossary->rssarticles = backup_todb($info['MOD']['#']['RSSARTICLES']['0']['#']);
        $glossary->timecreated = backup_todb($info['MOD']['#']['TIMECREATED']['0']['#']);
        $glossary->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
        $glossary->assessed = backup_todb($info['MOD']['#']['ASSESSED']['0']['#']);
        $glossary->assesstimestart = backup_todb($info['MOD']['#']['ASSESSTIMESTART']['0']['#']);
        $glossary->assesstimefinish = backup_todb($info['MOD']['#']['ASSESSTIMEFINISH']['0']['#']);
        $glossary->scale = backup_todb($info['MOD']['#']['SCALE']['0']['#']);
        //We have to recode the scale field if it's <0 (positive is a grade, not a scale)
        if ($glossary->scale < 0) {
            $scale = backup_getid($restore->backup_unique_code, "scale", abs($glossary->scale));
            if ($scale) {
                $glossary->scale = -$scale->new_id;
            }
        }
        //To mantain upwards compatibility (pre 1.4) we have to check the displayformat field
        //If it's numeric (0-6) we have to convert it to its new formatname.
        //Define current 0-6 format names
        $formatnames = array('dictionary', 'continuous', 'fullwithauthor', 'encyclopedia', 'faq', 'fullwithoutauthor', 'entrylist');
        //If it's numeric, we are restoring a pre 1.4 course, do the conversion
        if (is_numeric($glossary->displayformat)) {
            $displayformat = 'dictionary';
            //Default format
            if ($glossary->displayformat >= 0 && $glossary->displayformat <= 6) {
                $displayformat = $formatnames[$glossary->displayformat];
            }
            $glossary->displayformat = $displayformat;
        }
        //Now check that the displayformat exists in the server, else default to dictionary
        $formats = get_list_of_plugins('mod/glossary/formats');
        if (!in_array($glossary->displayformat, $formats)) {
            $glossary->displayformat = 'dictionary';
        }
        //If the backup file doesn't include the editalways field, activate it
        //in secondary glossaries (old behaviour, pre 1.4)
        if (!isset($info['MOD']['#']['EDITALWAYS']['0']['#'])) {
            //It's a pre-14 backup file
            if ($glossary->mainglossary == '0') {
                $glossary->editalways = '1';
            }
        }
        //The structure is equal to the db, so insert the glossary
        $newid = $DB->insert_record("glossary", $glossary);
        //Do some output
        if (!defined('RESTORE_SILENTLY')) {
            echo "<li>" . get_string("modulename", "glossary") . " \"" . format_string($glossary->name, true) . "\"</li>";
        }
        backup_flush(300);
        if ($newid) {
            //We have the newid, update backup_ids
            backup_putid($restore->backup_unique_code, $mod->modtype, $mod->id, $newid);
            //Restore glossary_entries
            $status = glossary_entries_restore_mods($mod->id, $newid, $info, $restore);
            //Restore glossary_categories and glossary_category_entries
            $status = glossary_categories_restore_mods($mod->id, $newid, $info, $restore);
        } else {
            $status = false;
        }
    } else {
        $status = false;
    }
    return $status;
}
Esempio n. 17
0
function restore_create_events($restore, $xml_file)
{
    global $CFG, $db;
    $status = true;
    //Check it exists
    if (!file_exists($xml_file)) {
        $status = false;
    }
    //Get info from xml
    if ($status) {
        //events will contain the old_id of every event
        //in backup_ids->info will be the real info (serialized)
        $events = restore_read_xml_events($restore, $xml_file);
    }
    //Get admin->id for later use
    $admin = get_admin();
    $adminid = $admin->id;
    //Now, if we have anything in events, we have to restore that
    //events
    if ($events) {
        if ($events !== true) {
            //Iterate over each event
            foreach ($events as $event) {
                //Get record from backup_ids
                $data = backup_getid($restore->backup_unique_code, "event", $event->id);
                //Init variables
                $create_event = false;
                if ($data) {
                    //Now get completed xmlized object
                    $info = $data->info;
                    //traverse_xmlize($info);                                                                     //Debug
                    //print_object ($GLOBALS['traverse_array']);                                                  //Debug
                    //$GLOBALS['traverse_array']="";                                                              //Debug
                    //if necessary, write to restorelog and adjust date/time fields
                    if ($restore->course_startdateoffset) {
                        restore_log_date_changes('Events', $restore, $info['EVENT']['#'], array('TIMESTART'));
                    }
                    //Now build the EVENT record structure
                    $eve->name = backup_todb($info['EVENT']['#']['NAME']['0']['#']);
                    $eve->description = backup_todb($info['EVENT']['#']['DESCRIPTION']['0']['#']);
                    $eve->format = backup_todb($info['EVENT']['#']['FORMAT']['0']['#']);
                    $eve->courseid = $restore->course_id;
                    $eve->groupid = backup_todb($info['EVENT']['#']['GROUPID']['0']['#']);
                    $eve->userid = backup_todb($info['EVENT']['#']['USERID']['0']['#']);
                    $eve->repeatid = backup_todb($info['EVENT']['#']['REPEATID']['0']['#']);
                    $eve->modulename = "";
                    if (!empty($info['EVENT']['#']['MODULENAME'])) {
                        $eve->modulename = backup_todb($info['EVENT']['#']['MODULENAME']['0']['#']);
                    }
                    $eve->instance = 0;
                    $eve->eventtype = backup_todb($info['EVENT']['#']['EVENTTYPE']['0']['#']);
                    $eve->timestart = backup_todb($info['EVENT']['#']['TIMESTART']['0']['#']);
                    $eve->timeduration = backup_todb($info['EVENT']['#']['TIMEDURATION']['0']['#']);
                    $eve->visible = backup_todb($info['EVENT']['#']['VISIBLE']['0']['#']);
                    $eve->timemodified = backup_todb($info['EVENT']['#']['TIMEMODIFIED']['0']['#']);
                    //Now search if that event exists (by name, description, timestart fields) in
                    //restore->course_id course
                    //Going to compare LOB columns so, use the cross-db sql_compare_text() in both sides.
                    $compare_description_clause = sql_compare_text('description') . "=" . sql_compare_text("'" . $eve->description . "'");
                    $eve_db = get_record_select("event", "courseid={$eve->courseid} AND name='{$eve->name}' AND {$compare_description_clause} AND timestart={$eve->timestart}");
                    //If it doesn't exist, create
                    if (!$eve_db) {
                        $create_event = true;
                    }
                    //If we must create the event
                    if ($create_event) {
                        //We must recode the userid
                        $user = backup_getid($restore->backup_unique_code, "user", $eve->userid);
                        if ($user) {
                            $eve->userid = $user->new_id;
                        } else {
                            //Assign it to admin
                            $eve->userid = $adminid;
                        }
                        //We have to recode the groupid field
                        $group = backup_getid($restore->backup_unique_code, "groups", $eve->groupid);
                        if ($group) {
                            $eve->groupid = $group->new_id;
                        } else {
                            //Assign it to group 0
                            $eve->groupid = 0;
                        }
                        //The structure is equal to the db, so insert the event
                        $newid = insert_record("event", $eve);
                        //We must recode the repeatid if the event has it
                        //The repeatid now refers to the id of the original event. (see Bug#5956)
                        if ($newid && !empty($eve->repeatid)) {
                            $repeat_rec = backup_getid($restore->backup_unique_code, "event_repeatid", $eve->repeatid);
                            if ($repeat_rec) {
                                //Exists, so use it...
                                $eve->repeatid = $repeat_rec->new_id;
                            } else {
                                //Doesn't exists, calculate the next and save it
                                $oldrepeatid = $eve->repeatid;
                                $eve->repeatid = $newid;
                                backup_putid($restore->backup_unique_code, "event_repeatid", $oldrepeatid, $eve->repeatid);
                            }
                            $eve->id = $newid;
                            // update the record to contain the correct repeatid
                            update_record('event', $eve);
                        }
                    } else {
                        //get current event id
                        $newid = $eve_db->id;
                    }
                    if ($newid) {
                        //We have the newid, update backup_ids
                        backup_putid($restore->backup_unique_code, "event", $event->id, $newid);
                    }
                }
            }
        }
    } else {
        $status = false;
    }
    return $status;
}
function booking_restore_mods($mod, $restore)
{
    global $CFG;
    $status = true;
    //Get record from backup_ids
    $data = backup_getid($restore->backup_unique_code, $mod->modtype, $mod->id);
    if ($data) {
        //Now get completed xmlized object
        $info = $data->info;
        // if necessary, write to restorelog and adjust date/time fields
        if ($restore->course_startdateoffset) {
            restore_log_date_changes('Booking', $restore, $info['MOD']['#'], array('TIMEOPEN', 'TIMECLOSE'));
        }
        //traverse_xmlize($info);                                                                     //Debug
        //print_object ($GLOBALS['traverse_array']);                                                  //Debug
        //$GLOBALS['traverse_array']="";                                                              //Debug
        //Now, build the BOOKING record structure
        $booking->course = $restore->course_id;
        $booking->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
        $booking->text = backup_todb($info['MOD']['#']['TEXT']['0']['#']);
        $booking->format = backup_todb($info['MOD']['#']['FORMAT']['0']['#']);
        $booking->bookingmanager = backup_todb($info['MOD']['#']['BOOKINGMANAGER']['0']['#']);
        $booking->sendmail = isset($info['MOD']['#']['SHOWINFO']['0']['#']) ? backup_todb($info['MOD']['#']['SENDMAIL']['0']['#']) : '';
        $booking->copymail = backup_todb($info['MOD']['#']['COPYMAIL']['0']['#']);
        $booking->allowupdate = backup_todb($info['MOD']['#']['ALLOWUPDATE']['0']['#']);
        $booking->bookingpolicy = backup_todb($info['MOD']['#']['bookingpolicy']['0']['#']);
        $booking->timeopen = backup_todb($info['MOD']['#']['TIMEOPEN']['0']['#']);
        $booking->timeclose = backup_todb($info['MOD']['#']['TIMECLOSE']['0']['#']);
        $booking->limitanswers = backup_todb($info['MOD']['#']['LIMITANSWERS']['0']['#']);
        $booking->maxanswers = backup_todb($info['MOD']['#']['MAXANSWERS']['0']['#']);
        $booking->maxoverbooking = backup_todb($info['MOD']['#']['MAXOVERBOOKING']['0']['#']);
        $booking->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
        $booking->duration = backup_todb($info['MOD']['#']['DURATION']['0']['#']);
        $booking->points = backup_todb($info['MOD']['#']['POINTS']['0']['#']);
        $booking->organizatorname = backup_todb($info['MOD']['#']['ORGANIZATORNAME']['0']['#']);
        $booking->pollurl = backup_todb($info['MOD']['#']['POLLURL']['0']['#']);
        $booking->addtogroup = backup_todb($info['MOD']['#']['ADDTOGROUP']['0']['#']);
        $booking->categoryid = backup_todb($info['MOD']['#']['CATEGORYID']['0']['#']);
        $booking->pollurltext = backup_todb($info['MOD']['#']['POLLURLTEXT']['0']['#']);
        $booking->additionalfields = backup_todb($info['MOD']['#']['ADDITIONALFIELDS']['0']['#']);
        $booking->eventtype = backup_todb($info['MOD']['#']['EVENTTYPE']['0']['#']);
        $booking->notificationtext = backup_todb($info['MOD']['#']['NOTIFICATIONTEXT']['0']['#']);
        $booking->userleave = backup_todb($info['MOD']['#']['USERLEAVE']['0']['#']);
        $booking->enablecompletion = backup_todb($info['MOD']['#']['ENABLECOMPLETION']['0']['#']);
        $booking->pollurlteachers = backup_todb($info['MOD']['#']['POLLURLTEACHERS']['0']['#']);
        $booking->pollurlteacherstext = backup_todb($info['MOD']['#']['POLLURLTEACHERSTEXT']['0']['#']);
        //The structure is equal to the db, so insert the booking
        $newid = insert_record("booking", $booking);
        if ($newid) {
            //We have the newid, update backup_ids
            backup_putid($restore->backup_unique_code, $mod->modtype, $mod->id, $newid);
            //Check to see how answers (curently booking_options) are stored in the table
            //If answer1 - answer6 exist, this is a pre 1.5 version of booking
            if (isset($info['MOD']['#']['ANSWER1']['0']['#']) || isset($info['MOD']['#']['ANSWER2']['0']['#']) || isset($info['MOD']['#']['ANSWER3']['0']['#']) || isset($info['MOD']['#']['ANSWER4']['0']['#']) || isset($info['MOD']['#']['ANSWER5']['0']['#']) || isset($info['MOD']['#']['ANSWER6']['0']['#'])) {
                //This is a pre 1.5 booking backup, special work begins
                $options = array();
                $options[1] = backup_todb($info['MOD']['#']['ANSWER1']['0']['#']);
                $options[2] = backup_todb($info['MOD']['#']['ANSWER2']['0']['#']);
                $options[3] = backup_todb($info['MOD']['#']['ANSWER3']['0']['#']);
                $options[4] = backup_todb($info['MOD']['#']['ANSWER4']['0']['#']);
                $options[5] = backup_todb($info['MOD']['#']['ANSWER5']['0']['#']);
                $options[6] = backup_todb($info['MOD']['#']['ANSWER6']['0']['#']);
                for ($i = 1; $i < 7; $i++) {
                    //insert old answers (in 1.4)  as booking_options (1.5) to db.
                    if (!empty($options[$i])) {
                        //make sure this option has something in it!
                        $option->bookingid = $newid;
                        $option->text = $options[$i];
                        $option->timemodified = $booking->timemodified;
                        $newoptionid = insert_record("booking_options", $option);
                        //Save this booking_option to backup_ids
                        backup_putid($restore->backup_unique_code, "booking_options", $i, $newoptionid);
                    }
                }
            } else {
                //Now we are in a "standard" 1.5 booking, so restore booking_options normally
                $status = booking_options_restore_mods($newid, $info, $restore);
            }
            //now restore the answers for this booking.
            if (restore_userdata_selected($restore, 'booking', $mod->id)) {
                //Restore booking_answers
                $status = booking_answers_restore_mods($newid, $info, $restore);
            }
        } else {
            $status = false;
        }
        //Do some output
        if (!defined('RESTORE_SILENTLY')) {
            echo "<li>" . get_string("modulename", "booking") . " \"" . format_string(stripslashes($booking->name), true) . "\"</li>";
        }
        backup_flush(300);
    } else {
        $status = false;
    }
    return $status;
}
Esempio n. 19
0
function exercise_restore_mods($mod, $restore)
{
    global $CFG;
    $status = true;
    //Get record from backup_ids
    $data = backup_getid($restore->backup_unique_code, $mod->modtype, $mod->id);
    if ($data) {
        //Now get completed xmlized object
        $info = $data->info;
        // if necessary, write to restorelog and adjust date/time fields
        if ($restore->course_startdateoffset) {
            restore_log_date_changes('Exercise', $restore, $info['MOD']['#'], array('DEADLINE'));
        }
        //traverse_xmlize($info);                                                              //Debug
        //print_object ($GLOBALS['traverse_array']);                                           //Debug
        //$GLOBALS['traverse_array']="";                                                       //Debug
        //Now, build the exercise record structure
        $exercise->course = $restore->course_id;
        $exercise->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
        $exercise->nelements = backup_todb($info['MOD']['#']['NELEMENTS']['0']['#']);
        $exercise->phase = backup_todb($info['MOD']['#']['PHASE']['0']['#']);
        $exercise->gradingstrategy = backup_todb($info['MOD']['#']['GRADINGSTRATEGY']['0']['#']);
        $exercise->usemaximum = backup_todb($info['MOD']['#']['USEMAXIMUM']['0']['#']);
        $exercise->assessmentcomps = backup_todb($info['MOD']['#']['ASSESSMENTCOMPS']['0']['#']);
        $exercise->anonymous = backup_todb($info['MOD']['#']['ANONYMOUS']['0']['#']);
        $exercise->maxbytes = backup_todb($info['MOD']['#']['MAXBYTES']['0']['#']);
        $exercise->deadline = backup_todb($info['MOD']['#']['DEADLINE']['0']['#']);
        $date = usergetdate($exercise->deadline);
        fwrite($restorelog_file, "<br/>The Exercise - " . $exercise->name . " <br/>");
        fwrite($restorelog_file, "The DEADLINE was  " . $date['weekday'] . ", " . $date['mday'] . " " . $date['month'] . " " . $date['year'] . "");
        $exercise->deadline += $restore->course_startdateoffset;
        $date = usergetdate($exercise->deadline);
        fwrite($restorelog_file, "&nbsp;&nbsp;&nbsp;the DEADLINE is now  " . $date['weekday'] . ",  " . $date['mday'] . " " . $date['month'] . " " . $date['year'] . "<br/>");
        $exercise->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
        $exercise->grade = backup_todb($info['MOD']['#']['GRADE']['0']['#']);
        $exercise->gradinggrade = backup_todb($info['MOD']['#']['GRADINGGRADE']['0']['#']);
        $exercise->showleaguetable = backup_todb($info['MOD']['#']['SHOWLEAGUETABLE']['0']['#']);
        $exercise->usepassword = backup_todb($info['MOD']['#']['USEPASSWORD']['0']['#']);
        $exercise->password = backup_todb($info['MOD']['#']['PASSWORD']['0']['#']);
        //The structure is equal to the db, so insert the exercise
        $newid = insert_record("exercise", $exercise);
        //Do some output
        if (!defined('RESTORE_SILENTLY')) {
            echo "<li>" . get_string("modulename", "exercise") . " \"" . format_string(stripslashes($exercise->name), true) . "\"</li>";
        }
        backup_flush(300);
        if ($newid) {
            //We have the newid, update backup_ids
            backup_putid($restore->backup_unique_code, $mod->modtype, $mod->id, $newid);
            //We have to restore the exercise_elements table now (course level table)
            $status = exercise_elements_restore($newid, $info, $restore);
            //restore the teacher submissions and optionally the student submissions
            $status = exercise_submissions_restore($mod->id, $newid, $info, $restore);
        } else {
            $status = false;
        }
    } else {
        $status = false;
    }
    return $status;
}
Esempio n. 20
0
function turnitintool_restore_mods($mod, $restore)
{
    global $CFG, $DB;
    $status = true;
    $data = backup_getid($restore->backup_unique_code, $mod->modtype, $mod->id);
    if ($data) {
        $info = $data->info;
        // Recreate the turnitintool_course entries
        $course = new stdClass();
        $course->id = backup_todb($info['MOD']['#']['COURSE']['0']['#']['ID']['0']['#']);
        $course->courseid = backup_todb($info['MOD']['#']['COURSE']['0']['#']['COURSEID']['0']['#']);
        $course->ownerid = backup_todb($info['MOD']['#']['COURSE']['0']['#']['OWNERID']['0']['#']);
        $course->turnitin_ctl = backup_todb($info['MOD']['#']['COURSE']['0']['#']['TURNITIN_CTL']['0']['#']);
        $course->turnitin_cid = backup_todb($info['MOD']['#']['COURSE']['0']['#']['TURNITIN_CID']['0']['#']);
        $course->ownertiiuid = backup_todb($info['MOD']['#']['COURSE']['0']['#']['OWNERTIIUID']['0']['#']);
        $course->ownerfn = backup_todb($info['MOD']['#']['COURSE']['0']['#']['OWNERFN']['0']['#']);
        $course->ownerln = backup_todb($info['MOD']['#']['COURSE']['0']['#']['OWNERLN']['0']['#']);
        $course->ownerun = backup_todb($info['MOD']['#']['COURSE']['0']['#']['OWNERUN']['0']['#']);
        $course->owneremail = backup_todb($info['MOD']['#']['COURSE']['0']['#']['OWNEREMAIL']['0']['#']);
        $tiicourseid = $course->turnitin_cid;
        // Determine if the destination course already has a TII Class associated, add check to determine the database call to enable backward compatibility
        // if it does is it the same class as the one we are restoring
        if (is_callable(array($DB, 'get_records_select'))) {
            $tiicourses = $DB->get_records_select('turnitintool_courses', 'turnitin_cid=' . $tiicourseid . ' OR courseid=' . $restore->course_id, null, "courseid", "id,courseid,turnitin_cid");
        } else {
            $tiicourses = get_records_select('turnitintool_courses', 'turnitin_cid=' . $tiicourseid . ' OR courseid=' . $restore->course_id, "courseid", "id,courseid,turnitin_cid");
        }
        $tiicourses = !$tiicourses ? array() : $tiicourses;
        $backupaccountid = $info['MOD']['#']['TIIACCOUNT']['0']['#'];
        if ($CFG->turnitin_account_id != $backupaccountid) {
            if (!defined('RESTORE_SILENTLY')) {
                // Course Error
                $input = new stdClass();
                $input->current = !empty($CFG->turnitin_account_id) ? $CFG->turnitin_account_id : '(' . get_string("notavailableyet", "turnitintool") . ')';
                $input->backupid = $backupaccountid;
                echo "<li class=\"error\">" . get_string("modulename", "turnitintool") . " : " . get_string("wrongaccountid", "turnitintool", $input) . "\"</li>";
            }
            return true;
            // Don't exit restore on failure...
        }
        $restorable = true;
        $thiscourse = false;
        foreach ($tiicourses as $tiicourse) {
            if ($tiicourse->turnitin_cid == $tiicourseid and $tiicourse->courseid != $restore->course_id or $tiicourse->turnitin_cid != $tiicourseid and $tiicourse->courseid == $restore->course_id) {
                // If the Turnitin Class ID exists against a course already
                // and that course is not the course we are restoring to then do not restore
                $restorable = false;
            } else {
                if ($tiicourse->courseid == $restore->course_id) {
                    $thiscourse = true;
                }
            }
        }
        // If the course class connection does not already exist OR if it does it is linked to this host course
        $insertcourse = new stdClass();
        $insertcourse->courseid = $restore->course_id;
        // If the owner had been deleted before back up then
        // the username email address thing will have happened
        $owneremail = empty($course->owneremail) ? join(array_splice(explode(".", $course->ownerun), 0, -1)) : $course->owneremail;
        if (is_callable(array($DB, 'get_records'))) {
            $owner = $DB->get_record('user', array('email' => $owneremail));
        } else {
            $owner = get_record('user', 'email', $owneremail);
        }
        if ($owner) {
            $insertcourse->ownerid = $owner->id;
        } else {
            // Turnitin class owner not found from email address etc create user account
            $newuser = false;
            $i = 0;
            while (!$newuser) {
                // Keep trying to create a new username
                $username = $i == 0 ? $course->ownerun : $course->ownerun . '_' . $i;
                // Append number if username exists
                $i++;
                $newuser = create_user_record($username, substr(rand(0, 9) . '_' . md5($course->ownerun), 0, 8));
                $newuser->email = $owneremail;
                $newuser->firstname = $course->ownerfn;
                $newuser->lastname = $course->ownerln;
                if (is_callable(array($DB, 'update_record'))) {
                    $DB->update_record("turnitintool_courses", $newuser);
                } else {
                    update_record("turnitintool_courses", $newuser);
                }
            }
            $insertcourse->ownerid = $newuser->id;
        }
        $insertcourse->turnitin_ctl = $course->turnitin_ctl;
        $insertcourse->turnitin_cid = $course->turnitin_cid;
        if (is_callable(array($DB, 'insert_record')) and !$thiscourse) {
            $DB->insert_record("turnitintool_courses", $insertcourse);
        } else {
            if (!$thiscourse) {
                insert_record("turnitintool_courses", $insertcourse);
            }
        }
        if ($restore->course_startdateoffset) {
            restore_log_date_changes(get_string('modulename', 'turnitintool'), $restore, $info['MOD']['#'], array('TIMEDUE', 'TIMEAVAILABLE'));
        }
        $turnitintool->course = $restore->course_id;
        $turnitintool->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
        $turnitintool->grade = backup_todb($info['MOD']['#']['GRADE']['0']['#']);
        $turnitintool->numparts = backup_todb($info['MOD']['#']['NUMPARTS']['0']['#']);
        $turnitintool->defaultdtstart = backup_todb($info['MOD']['#']['DEFAULTDTSTART']['0']['#']);
        $turnitintool->defaultdtdue = backup_todb($info['MOD']['#']['DEFAULTDTDUE']['0']['#']);
        $turnitintool->defaultdtpost = backup_todb($info['MOD']['#']['DEFAULTDTPOST']['0']['#']);
        $turnitintool->anon = backup_todb($info['MOD']['#']['ANON']['0']['#']);
        $turnitintool->portfolio = backup_todb($info['MOD']['#']['PORTFOLIO']['0']['#']);
        $turnitintool->allowlate = backup_todb($info['MOD']['#']['ALLOWLATE']['0']['#']);
        $turnitintool->reportgenspeed = backup_todb($info['MOD']['#']['REPORTGENSPEED']['0']['#']);
        $turnitintool->submitpapersto = backup_todb($info['MOD']['#']['SUBMITPAPERSTO']['0']['#']);
        $turnitintool->spapercheck = backup_todb($info['MOD']['#']['SPAPERCHECK']['0']['#']);
        $turnitintool->internetcheck = backup_todb($info['MOD']['#']['INTERNETCHECK']['0']['#']);
        $turnitintool->journalcheck = backup_todb($info['MOD']['#']['JOURNALCHECK']['0']['#']);
        $turnitintool->maxfilesize = backup_todb($info['MOD']['#']['MAXFILESIZE']['0']['#']);
        $turnitintool->intro = backup_todb($info['MOD']['#']['INTRO']['0']['#']);
        $turnitintool->introformat = backup_todb($info['MOD']['#']['INTROFORMAT']['0']['#']);
        $turnitintool->timecreated = backup_todb($info['MOD']['#']['TIMECREATED']['0']['#']);
        $turnitintool->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
        $turnitintool->studentreports = backup_todb($info['MOD']['#']['STUDENTREPORTS']['0']['#']);
        $turnitintool->dateformat = backup_todb($info['MOD']['#']['DATEFORMAT']['0']['#']);
        $turnitintool->usegrademark = backup_todb($info['MOD']['#']['USEGRADEMARK']['0']['#']);
        $turnitintool->gradedisplay = backup_todb($info['MOD']['#']['GRADEDISPLAY']['0']['#']);
        $turnitintool->autoupdates = backup_todb($info['MOD']['#']['AUTOUPDATES']['0']['#']);
        $turnitintool->commentedittime = backup_todb($info['MOD']['#']['COMMENTEDITTIME']['0']['#']);
        $turnitintool->commentmaxsize = backup_todb($info['MOD']['#']['COMMENTMAXSIZE']['0']['#']);
        $turnitintool->autosubmission = backup_todb($info['MOD']['#']['AUTOSUBMISSION']['0']['#']);
        $turnitintool->shownonsubmission = backup_todb($info['MOD']['#']['SHOWNONSUBMISSION']['0']['#']);
        // Add exclude small matches data if present in backup file
        if (isset($info['MOD']['#']['EXCLUDEBIBLIO']['0']['#'])) {
            $turnitintool->excludebiblio = backup_todb($info['MOD']['#']['EXCLUDEBIBLIO']['0']['#']);
            $turnitintool->excludequoted = backup_todb($info['MOD']['#']['EXCLUDEQUOTED']['0']['#']);
            $turnitintool->excludevalue = backup_todb($info['MOD']['#']['EXCLUDEVALUE']['0']['#']);
            $turnitintool->excludetype = backup_todb($info['MOD']['#']['EXCLUDETYPE']['0']['#']);
        }
        // Add exclude small matches data if present in backup file
        if (isset($info['MOD']['#']['ERATER']['0']['#'])) {
            $turnitintool->erater = backup_todb($info['MOD']['#']['ERATER']['0']['#']);
            $turnitintool->erater_handbook = backup_todb($info['MOD']['#']['ERATERHANDBOOK']['0']['#']);
            $turnitintool->erater_dictionary = backup_todb($info['MOD']['#']['ERATERDICTIONARY']['0']['#']);
            $turnitintool->erater_spelling = backup_todb($info['MOD']['#']['ERATERSPELLING']['0']['#']);
            $turnitintool->erater_grammar = backup_todb($info['MOD']['#']['ERATERGRAMMAR']['0']['#']);
            $turnitintool->erater_usage = backup_todb($info['MOD']['#']['ERATERUSAGE']['0']['#']);
            $turnitintool->erater_mechanics = backup_todb($info['MOD']['#']['ERATERMECHANICS']['0']['#']);
            $turnitintool->erater_style = backup_todb($info['MOD']['#']['ERATERSTYLE']['0']['#']);
        }
        if (is_callable(array($DB, 'insert_record'))) {
            $newid = $DB->insert_record("turnitintool", $turnitintool);
        } else {
            $newid = insert_record("turnitintool", $turnitintool);
        }
        // Recreate the turnitintool_parts entries
        $newpartids = array();
        foreach ($info['MOD']['#']['PARTS']['0']['#']['PART'] as $partarray) {
            $part = new stdClass();
            $part->turnitintoolid = $newid;
            $part->partname = backup_todb($partarray['#']['PARTNAME']['0']['#']);
            $part->tiiassignid = backup_todb($partarray['#']['TIIASSIGNID']['0']['#']);
            $part->dtstart = backup_todb($partarray['#']['DTSTART']['0']['#']);
            $part->dtdue = backup_todb($partarray['#']['DTDUE']['0']['#']);
            $part->dtpost = backup_todb($partarray['#']['DTPOST']['0']['#']);
            $part->maxmarks = backup_todb($partarray['#']['MAXMARKS']['0']['#']);
            $part->deleted = backup_todb($partarray['#']['DELETED']['0']['#']);
            $oldpartid = backup_todb($partarray['#']['ID']['0']['#']);
            unset($part->id);
            if (is_callable(array($DB, 'insert_record'))) {
                $newpartid = $DB->insert_record("turnitintool_parts", $part);
            } else {
                $newpartid = insert_record("turnitintool_parts", $part);
            }
            $newpartids[$oldpartid] = $newpartid;
        }
        if (!defined('RESTORE_SILENTLY')) {
            echo "<li>" . get_string("modulename", "turnitintool") . " \"" . format_string(stripslashes($turnitintool->name), true) . "\"</li>";
        }
        backup_flush(300);
        if ($newid) {
            backup_putid($restore->backup_unique_code, $mod->modtype, $mod->id, $newid);
            if (restore_userdata_selected($restore, 'turnitintool', $mod->id)) {
                $status = turnitintool_submissions_restore_mods($mod->id, $newid, $newpartids, $info, $restore) && $status;
            }
        } else {
            $status = false;
        }
    } else {
        $status = false;
    }
    return $status;
}
Esempio n. 21
0
function lesson_restore_mods($mod, $restore)
{
    global $CFG;
    $status = true;
    //Get record from backup_ids
    $data = backup_getid($restore->backup_unique_code, $mod->modtype, $mod->id);
    if ($data) {
        //Now get completed xmlized object
        $info = $data->info;
        //if necessary, write to restorelog and adjust date/time fields
        if ($restore->course_startdateoffset) {
            restore_log_date_changes('Lesson', $restore, $info['MOD']['#'], array('AVAILABLE', 'DEADLINE'));
        }
        //traverse_xmlize($info);                                                              //Debug
        //print_object ($GLOBALS['traverse_array']);                                           //Debug
        //$GLOBALS['traverse_array']="";                                                       //Debug
        //Now, build the lesson record structure
        $lesson->course = $restore->course_id;
        $lesson->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
        $lesson->practice = backup_todb($info['MOD']['#']['PRACTICE']['0']['#']);
        $lesson->modattempts = backup_todb($info['MOD']['#']['MODATTEMPTS']['0']['#']);
        $lesson->usepassword = backup_todb($info['MOD']['#']['USEPASSWORD']['0']['#']);
        $lesson->password = backup_todb($info['MOD']['#']['PASSWORD']['0']['#']);
        $lesson->dependency = isset($info['MOD']['#']['DEPENDENCY']['0']['#']) ? backup_todb($info['MOD']['#']['DEPENDENCY']['0']['#']) : '';
        $lesson->conditions = isset($info['MOD']['#']['CONDITIONS']['0']['#']) ? backup_todb($info['MOD']['#']['CONDITIONS']['0']['#']) : '';
        $lesson->grade = backup_todb($info['MOD']['#']['GRADE']['0']['#']);
        $lesson->custom = backup_todb($info['MOD']['#']['CUSTOM']['0']['#']);
        $lesson->ongoing = backup_todb($info['MOD']['#']['ONGOING']['0']['#']);
        $lesson->usemaxgrade = backup_todb($info['MOD']['#']['USEMAXGRADE']['0']['#']);
        $lesson->maxanswers = backup_todb($info['MOD']['#']['MAXANSWERS']['0']['#']);
        $lesson->maxattempts = backup_todb($info['MOD']['#']['MAXATTEMPTS']['0']['#']);
        $lesson->review = backup_todb($info['MOD']['#']['REVIEW']['0']['#']);
        $lesson->nextpagedefault = backup_todb($info['MOD']['#']['NEXTPAGEDEFAULT']['0']['#']);
        $lesson->feedback = isset($info['MOD']['#']['FEEDBACK']['0']['#']) ? backup_todb($info['MOD']['#']['FEEDBACK']['0']['#']) : '';
        $lesson->minquestions = backup_todb($info['MOD']['#']['MINQUESTIONS']['0']['#']);
        $lesson->maxpages = backup_todb($info['MOD']['#']['MAXPAGES']['0']['#']);
        $lesson->timed = backup_todb($info['MOD']['#']['TIMED']['0']['#']);
        $lesson->maxtime = backup_todb($info['MOD']['#']['MAXTIME']['0']['#']);
        $lesson->retake = backup_todb($info['MOD']['#']['RETAKE']['0']['#']);
        $lesson->activitylink = isset($info['MOD']['#']['ACTIVITYLINK']['0']['#']) ? backup_todb($info['MOD']['#']['ACTIVITYLINK']['0']['#']) : '';
        $lesson->mediafile = isset($info['MOD']['#']['MEDIAFILE']['0']['#']) ? backup_todb($info['MOD']['#']['MEDIAFILE']['0']['#']) : '';
        $lesson->mediaheight = isset($info['MOD']['#']['MEDIAHEIGHT']['0']['#']) ? backup_todb($info['MOD']['#']['MEDIAHEIGHT']['0']['#']) : '';
        $lesson->mediawidth = isset($info['MOD']['#']['MEDIAWIDTH']['0']['#']) ? backup_todb($info['MOD']['#']['MEDIAWIDTH']['0']['#']) : '';
        $lesson->mediaclose = isset($info['MOD']['#']['MEDIACLOSE']['0']['#']) ? backup_todb($info['MOD']['#']['MEDIACLOSE']['0']['#']) : '';
        $lesson->slideshow = backup_todb($info['MOD']['#']['SLIDESHOW']['0']['#']);
        $lesson->width = backup_todb($info['MOD']['#']['WIDTH']['0']['#']);
        $lesson->height = backup_todb($info['MOD']['#']['HEIGHT']['0']['#']);
        $lesson->bgcolor = backup_todb($info['MOD']['#']['BGCOLOR']['0']['#']);
        $lesson->displayleft = isset($info['MOD']['#']['DISPLAYLEFT']['0']['#']) ? backup_todb($info['MOD']['#']['DISPLAYLEFT']['0']['#']) : '';
        $lesson->displayleftif = isset($info['MOD']['#']['DISPLAYLEFTIF']['0']['#']) ? backup_todb($info['MOD']['#']['DISPLAYLEFTIF']['0']['#']) : '';
        $lesson->progressbar = isset($info['MOD']['#']['PROGRESSBAR']['0']['#']) ? backup_todb($info['MOD']['#']['PROGRESSBAR']['0']['#']) : '';
        $lesson->highscores = backup_todb($info['MOD']['#']['SHOWHIGHSCORES']['0']['#']);
        $lesson->maxhighscores = backup_todb($info['MOD']['#']['MAXHIGHSCORES']['0']['#']);
        $lesson->available = backup_todb($info['MOD']['#']['AVAILABLE']['0']['#']);
        $lesson->deadline = backup_todb($info['MOD']['#']['DEADLINE']['0']['#']);
        $lesson->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
        //The structure is equal to the db, so insert the lesson
        $newid = insert_record("lesson", $lesson);
        //Do some output
        if (!defined('RESTORE_SILENTLY')) {
            echo "<li>" . get_string("modulename", "lesson") . " \"" . format_string(stripslashes($lesson->name), true) . "\"</li>";
        }
        backup_flush(300);
        if ($newid) {
            //We have the newid, update backup_ids
            backup_putid($restore->backup_unique_code, $mod->modtype, $mod->id, $newid);
            //We have to restore the lesson pages which are held in their logical order...
            $userdata = restore_userdata_selected($restore, "lesson", $mod->id);
            $status = lesson_pages_restore_mods($newid, $info, $restore, $userdata);
            //...and the user grades, high scores, and timer (if required)
            if ($status) {
                if ($userdata) {
                    if (!lesson_grades_restore_mods($newid, $info, $restore)) {
                        return false;
                    }
                    if (!lesson_high_scores_restore_mods($newid, $info, $restore)) {
                        return false;
                    }
                    if (!lesson_timer_restore_mods($newid, $info, $restore)) {
                        return false;
                    }
                }
                // restore the default for the course.  Only do this once by checking for an id for lesson_default
                $lessondefault = backup_getid($restore->backup_unique_code, 'lesson_default', $restore->course_id);
                if (!$lessondefault) {
                    $status = lesson_default_restore_mods($info, $restore);
                }
            }
        } else {
            $status = false;
        }
    } else {
        $status = false;
    }
    return $status;
}
Esempio n. 22
0
function choice_restore_mods($mod, $restore)
{
    global $CFG;
    $status = true;
    //Get record from backup_ids
    $data = backup_getid($restore->backup_unique_code, $mod->modtype, $mod->id);
    if ($data) {
        //Now get completed xmlized object
        $info = $data->info;
        // if necessary, write to restorelog and adjust date/time fields
        if ($restore->course_startdateoffset) {
            restore_log_date_changes('Choice', $restore, $info['MOD']['#'], array('TIMEOPEN', 'TIMECLOSE'));
        }
        //traverse_xmlize($info);                                                                     //Debug
        //print_object ($GLOBALS['traverse_array']);                                                  //Debug
        //$GLOBALS['traverse_array']="";                                                              //Debug
        //Now, build the CHOICE record structure
        $choice->course = $restore->course_id;
        $choice->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
        $choice->text = backup_todb($info['MOD']['#']['TEXT']['0']['#']);
        $choice->format = backup_todb($info['MOD']['#']['FORMAT']['0']['#']);
        $choice->publish = backup_todb($info['MOD']['#']['PUBLISH']['0']['#']);
        $choice->showresults = isset($info['MOD']['#']['SHOWRESULTS']['0']['#']) ? backup_todb($info['MOD']['#']['SHOWRESULTS']['0']['#']) : '';
        $choice->display = backup_todb($info['MOD']['#']['DISPLAY']['0']['#']);
        $choice->allowupdate = backup_todb($info['MOD']['#']['ALLOWUPDATE']['0']['#']);
        $choice->showunanswered = backup_todb($info['MOD']['#']['SHOWUNANSWERED']['0']['#']);
        $choice->limitanswers = backup_todb($info['MOD']['#']['LIMITANSWERS']['0']['#']);
        $choice->timeopen = backup_todb($info['MOD']['#']['TIMEOPEN']['0']['#']);
        $choice->timeclose = backup_todb($info['MOD']['#']['TIMECLOSE']['0']['#']);
        $choice->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
        //To mantain compatibilty, in 1.4 the publish setting meaning has changed. We
        //have to modify some things it if the release field isn't present in the backup file.
        if (!isset($info['MOD']['#']['SHOWRESULTS']['0']['#'])) {
            //check for previous versions
            if (!isset($info['MOD']['#']['RELEASE']['0']['#'])) {
                //It's a pre-14 backup filea
                //Set the allowupdate field
                if ($choice->publish == 0) {
                    $choice->allowupdate = 1;
                }
                //Set the showresults field as defined by the old publish field
                if ($choice->publish > 0) {
                    $choice->showresults = 1;
                }
                //Recode the publish field to its 1.4 meaning
                if ($choice->publish > 0) {
                    $choice->publish--;
                }
            } else {
                //it's post 1.4 pre 1.6
                //convert old release values into new showanswer column.
                $choice->showresults = backup_todb($info['MOD']['#']['RELEASE']['0']['#']);
            }
        }
        //The structure is equal to the db, so insert the choice
        $newid = insert_record("choice", $choice);
        if ($newid) {
            //We have the newid, update backup_ids
            backup_putid($restore->backup_unique_code, $mod->modtype, $mod->id, $newid);
            //Check to see how answers (curently choice_options) are stored in the table
            //If answer1 - answer6 exist, this is a pre 1.5 version of choice
            if (isset($info['MOD']['#']['ANSWER1']['0']['#']) || isset($info['MOD']['#']['ANSWER2']['0']['#']) || isset($info['MOD']['#']['ANSWER3']['0']['#']) || isset($info['MOD']['#']['ANSWER4']['0']['#']) || isset($info['MOD']['#']['ANSWER5']['0']['#']) || isset($info['MOD']['#']['ANSWER6']['0']['#'])) {
                //This is a pre 1.5 choice backup, special work begins
                $options = array();
                $options[1] = backup_todb($info['MOD']['#']['ANSWER1']['0']['#']);
                $options[2] = backup_todb($info['MOD']['#']['ANSWER2']['0']['#']);
                $options[3] = backup_todb($info['MOD']['#']['ANSWER3']['0']['#']);
                $options[4] = backup_todb($info['MOD']['#']['ANSWER4']['0']['#']);
                $options[5] = backup_todb($info['MOD']['#']['ANSWER5']['0']['#']);
                $options[6] = backup_todb($info['MOD']['#']['ANSWER6']['0']['#']);
                for ($i = 1; $i < 7; $i++) {
                    //insert old answers (in 1.4)  as choice_options (1.5) to db.
                    if (!empty($options[$i])) {
                        //make sure this option has something in it!
                        $option->choiceid = $newid;
                        $option->text = $options[$i];
                        $option->timemodified = $choice->timemodified;
                        $newoptionid = insert_record("choice_options", $option);
                        //Save this choice_option to backup_ids
                        backup_putid($restore->backup_unique_code, "choice_options", $i, $newoptionid);
                    }
                }
            } else {
                //Now we are in a "standard" 1.5 choice, so restore choice_options normally
                $status = choice_options_restore_mods($newid, $info, $restore);
            }
            //now restore the answers for this choice.
            if (restore_userdata_selected($restore, 'choice', $mod->id)) {
                //Restore choice_answers
                $status = choice_answers_restore_mods($newid, $info, $restore);
            }
        } else {
            $status = false;
        }
        //Do some output
        if (!defined('RESTORE_SILENTLY')) {
            echo "<li>" . get_string("modulename", "choice") . " \"" . format_string(stripslashes($choice->name), true) . "\"</li>";
        }
        backup_flush(300);
    } else {
        $status = false;
    }
    return $status;
}
Esempio n. 23
0
function assignment_restore_mods($mod, $restore)
{
    global $CFG;
    $status = true;
    //Get record from backup_ids
    $data = backup_getid($restore->backup_unique_code, $mod->modtype, $mod->id);
    if ($data) {
        //Now get completed xmlized object
        $info = $data->info;
        //if necessary, write to restorelog and adjust date/time fields
        if ($restore->course_startdateoffset) {
            restore_log_date_changes('Assignment', $restore, $info['MOD']['#'], array('TIMEDUE', 'TIMEAVAILABLE'));
        }
        //traverse_xmlize($info);                                                                     //Debug
        //print_object ($GLOBALS['traverse_array']);                                                  //Debug
        //$GLOBALS['traverse_array']="";                                                              //Debug
        //Now, build the ASSIGNMENT record structure
        $assignment->course = $restore->course_id;
        $assignment->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
        $assignment->description = backup_todb($info['MOD']['#']['DESCRIPTION']['0']['#']);
        $assignment->format = backup_todb($info['MOD']['#']['FORMAT']['0']['#']);
        $assignment->resubmit = backup_todb($info['MOD']['#']['RESUBMIT']['0']['#']);
        $assignment->preventlate = backup_todb($info['MOD']['#']['PREVENTLATE']['0']['#']);
        $assignment->emailteachers = backup_todb($info['MOD']['#']['EMAILTEACHERS']['0']['#']);
        $assignment->var1 = backup_todb($info['MOD']['#']['VAR1']['0']['#']);
        $assignment->var2 = backup_todb($info['MOD']['#']['VAR2']['0']['#']);
        $assignment->var3 = backup_todb($info['MOD']['#']['VAR3']['0']['#']);
        $assignment->var4 = backup_todb($info['MOD']['#']['VAR4']['0']['#']);
        $assignment->var5 = backup_todb($info['MOD']['#']['VAR5']['0']['#']);
        $assignment->type = isset($info['MOD']['#']['TYPE']['0']['#']) ? backup_todb($info['MOD']['#']['TYPE']['0']['#']) : '';
        $assignment->assignmenttype = backup_todb($info['MOD']['#']['ASSIGNMENTTYPE']['0']['#']);
        $assignment->maxbytes = backup_todb($info['MOD']['#']['MAXBYTES']['0']['#']);
        $assignment->timedue = backup_todb($info['MOD']['#']['TIMEDUE']['0']['#']);
        $assignment->timeavailable = backup_todb($info['MOD']['#']['TIMEAVAILABLE']['0']['#']);
        $assignment->grade = backup_todb($info['MOD']['#']['GRADE']['0']['#']);
        $assignment->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
        //We have to recode the grade field if it is <0 (scale)
        if ($assignment->grade < 0) {
            $scale = backup_getid($restore->backup_unique_code, "scale", abs($assignment->grade));
            if ($scale) {
                $assignment->grade = -$scale->new_id;
            }
        }
        if (empty($assignment->assignmenttype)) {
            /// Pre 1.5 assignment
            if ($assignment->type == 1) {
                $assignment->assignmenttype = 'uploadsingle';
            } else {
                $assignment->assignmenttype = 'offline';
            }
        }
        // skip restore of plugins that are not installed
        static $plugins;
        if (!isset($plugins)) {
            $plugins = get_list_of_plugins('mod/assignment/type');
        }
        if (!in_array($assignment->assignmenttype, $plugins)) {
            if (!defined('RESTORE_SILENTLY')) {
                echo "<li><strong>" . get_string("modulename", "assignment") . " \"" . format_string(stripslashes($assignment->name), true) . "\" - plugin '{$assignment->assignmenttype}' not available!</strong></li>";
            }
            return true;
            // do not fail the restore
        }
        //The structure is equal to the db, so insert the assignment
        $newid = insert_record("assignment", $assignment);
        //Do some output
        if (!defined('RESTORE_SILENTLY')) {
            echo "<li>" . get_string("modulename", "assignment") . " \"" . format_string(stripslashes($assignment->name), true) . "\"</li>";
        }
        backup_flush(300);
        if ($newid) {
            //We have the newid, update backup_ids
            backup_putid($restore->backup_unique_code, $mod->modtype, $mod->id, $newid);
            // load up the subtype and see if it wants anything further restored.
            $class = 'assignment_' . $assignment->assignmenttype;
            require_once $CFG->dirroot . '/mod/assignment/lib.php';
            require_once $CFG->dirroot . '/mod/assignment/type/' . $assignment->assignmenttype . '/assignment.class.php';
            call_user_func(array($class, 'restore_one_mod'), $info, $restore, $assignment);
            //Now check if want to restore user data and do it.
            if (restore_userdata_selected($restore, 'assignment', $mod->id)) {
                //Restore assignmet_submissions
                $status = assignment_submissions_restore_mods($mod->id, $newid, $info, $restore, $assignment) && $status;
            }
        } else {
            $status = false;
        }
    } else {
        $status = false;
    }
    return $status;
}
function econsole_restore_mods($mod, $restore)
{
    global $CFG;
    $status = true;
    //Get record from backup_ids
    $data = backup_getid($restore->backup_unique_code, $mod->modtype, $mod->id);
    if ($data) {
        //Now get completed xmlized object
        $info = $data->info;
        //traverse_xmlize($info);                                                                     //Debug
        //print_object ($GLOBALS['traverse_array']);                                                  //Debug
        //$GLOBALS['traverse_array']="";                                                              //Debug
        // if necessary, write to restorelog and adjust date/time fields
        if ($restore->course_startdateoffset) {
            restore_log_date_changes('E-Console', $restore, $info['MOD']['#'], array('CONSOLETRERSTIME'));
        }
        //Now, build the CONSOLETRERS record structure
        $econsole->course = $restore->course_id;
        $econsole->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
        $econsole->content = backup_todb($info['MOD']['#']['CONTENT']['0']['#']);
        $econsole->unitstring = backup_todb($info['MOD']['#']['UNITSTRING']['0']['#']);
        $econsole->showunit = backup_todb($info['MOD']['#']['SHOWUNIT']['0']['#']);
        $econsole->lessonstring = backup_todb($info['MOD']['#']['LESSONSTRING']['0']['#']);
        $econsole->showlesson = backup_todb($info['MOD']['#']['SHOWLESSON']['0']['#']);
        $econsole->url1name = backup_todb($info['MOD']['#']['URL1NAME']['0']['#']);
        $econsole->url1 = backup_todb($info['MOD']['#']['URL1']['0']['#']);
        $econsole->url2name = backup_todb($info['MOD']['#']['URL2NAME']['0']['#']);
        $econsole->url2 = backup_todb($info['MOD']['#']['URL2']['0']['#']);
        $econsole->url3name = backup_todb($info['MOD']['#']['URL3NAME']['0']['#']);
        $econsole->url3 = backup_todb($info['MOD']['#']['URL3']['0']['#']);
        $econsole->url4name = backup_todb($info['MOD']['#']['URL4NAME']['0']['#']);
        $econsole->url4 = backup_todb($info['MOD']['#']['URL4']['0']['#']);
        $econsole->url5name = backup_todb($info['MOD']['#']['URL5NAME']['0']['#']);
        $econsole->url5 = backup_todb($info['MOD']['#']['URL5']['0']['#']);
        $econsole->url6name = backup_todb($info['MOD']['#']['URL6NAME']['0']['#']);
        $econsole->url6 = backup_todb($info['MOD']['#']['URL6']['0']['#']);
        $econsole->glossary = backup_todb($info['MOD']['#']['GLOSSARY']['0']['#']);
        $econsole->journal = backup_todb($info['MOD']['#']['JOURNAL']['0']['#']);
        $econsole->forum = backup_todb($info['MOD']['#']['FORUM']['0']['#']);
        $econsole->chat = backup_todb($info['MOD']['#']['CHAT']['0']['#']);
        $econsole->choice = backup_todb($info['MOD']['#']['CHOICE']['0']['#']);
        $econsole->quiz = backup_todb($info['MOD']['#']['QUIZ']['0']['#']);
        $econsole->assignment = backup_todb($info['MOD']['#']['ASSIGNMENT']['0']['#']);
        $econsole->wiki = backup_todb($info['MOD']['#']['WIKI']['0']['#']);
        $econsole->theme = backup_todb($info['MOD']['#']['THEME']['0']['#']);
        $econsole->imagebartop = backup_todb($info['MOD']['#']['IMAGEBARTOP']['0']['#']);
        $econsole->imagebarbottom = backup_todb($info['MOD']['#']['IMAGEBARBOTTOM']['0']['#']);
        $econsole->timecreated = backup_todb($info['MOD']['#']['TIMECREATED']['0']['#']);
        $econsole->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
        //The structure is equal to the db, so insert the econsole
        $newid = insert_record("econsole", $econsole);
        //Do some output
        if (!defined('RESTORE_SILENTLY')) {
            echo "<li>" . get_string("modulename", "econsole") . " \"" . format_string(stripslashes($econsole->name), true) . "\"</li>";
        }
        backup_flush(300);
        if ($newid) {
            //We have the newid, update backup_ids
            backup_putid($restore->backup_unique_code, $mod->modtype, $mod->id, $newid);
            //Now check if want to restore user data and do it.
            /*                if (restore_userdata_selected($restore,'econsole',$mod->id)) {
                                //Restore econsole_messages
                                $status = econsole_messages_restore_mods ($mod->id, $newid,$info,$restore);
                            }
            */
        } else {
            $status = false;
        }
    } else {
        $status = false;
    }
    return $status;
}
function webquestscorm_restore_mods($mod, $restore)
{
    global $CFG;
    $status = true;
    //Get record from backup_ids
    $data = backup_getid($restore->backup_unique_code, $mod->modtype, $mod->id);
    if ($data) {
        //Now get completed xmlized object
        $info = $data->info;
        //if necessary, write to restorelog and adjust date/time fields
        if ($restore->course_startdateoffset) {
            restore_log_date_changes('Webquestscorm', $restore, $info['MOD']['#'], array('TIMEDUE', 'TIMEAVAILABLE'));
        }
        //traverse_xmlize($info);                                                                     //Debug
        //print_object ($GLOBALS['traverse_array']);                                                  //Debug
        //$GLOBALS['traverse_array']="";                                                              //Debug
        //Now, build the webquestscorm record structure
        $webquestscorm->course = $restore->course_id;
        $webquestscorm->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
        $webquestscorm->grade = backup_todb($info['MOD']['#']['GRADE']['0']['#']);
        $webquestscorm->timeavailable = backup_todb($info['MOD']['#']['TIMEAVAILABLE']['0']['#']);
        $webquestscorm->timedue = backup_todb($info['MOD']['#']['TIMEDUE']['0']['#']);
        $webquestscorm->dueenable = backup_todb($info['MOD']['#']['DUEENABLE']['0']['#']);
        $webquestscorm->dueyear = backup_todb($info['MOD']['#']['DUEYEAR']['0']['#']);
        $webquestscorm->duemonth = backup_todb($info['MOD']['#']['DUEMONTH']['0']['#']);
        $webquestscorm->dueday = backup_todb($info['MOD']['#']['DUEDAY']['0']['#']);
        $webquestscorm->duehour = backup_todb($info['MOD']['#']['DUEHOUR']['0']['#']);
        $webquestscorm->dueminute = backup_todb($info['MOD']['#']['DUEMINUTE']['0']['#']);
        $webquestscorm->availableenable = backup_todb($info['MOD']['#']['AVAILABLEENABLE']['0']['#']);
        $webquestscorm->availableyear = backup_todb($info['MOD']['#']['AVAILABLEYEAR']['0']['#']);
        $webquestscorm->availablemonth = backup_todb($info['MOD']['#']['AVAILABLEMONTH']['0']['#']);
        $webquestscorm->availableday = backup_todb($info['MOD']['#']['AVAILABLEDAY']['0']['#']);
        $webquestscorm->availablehour = backup_todb($info['MOD']['#']['AVAILABLEHOUR']['0']['#']);
        $webquestscorm->availableminute = isset($info['MOD']['#']['AVAILABLEMINUTE']['0']['#']) ? backup_todb($info['MOD']['#']['TYPE']['0']['#']) : '';
        $webquestscorm->maxbytes = backup_todb($info['MOD']['#']['MAXBYTES']['0']['#']);
        $webquestscorm->preventlate = backup_todb($info['MOD']['#']['PREVENTLATE']['0']['#']);
        $webquestscorm->resubmit = backup_todb($info['MOD']['#']['RESUBMIT']['0']['#']);
        $webquestscorm->emailteachers = backup_todb($info['MOD']['#']['EMAILTEACHERS']['0']['#']);
        $webquestscorm->template = backup_todb($info['MOD']['#']['TEMPLATE']['0']['#']);
        $webquestscorm->introduction = backup_todb($info['MOD']['#']['INTRODUCTION']['0']['#']);
        $webquestscorm->task = backup_todb($info['MOD']['#']['TASK']['0']['#']);
        $webquestscorm->process = backup_todb($info['MOD']['#']['PROCESS']['0']['#']);
        $webquestscorm->evaluation = backup_todb($info['MOD']['#']['EVALUATION']['0']['#']);
        $webquestscorm->conclusion = backup_todb($info['MOD']['#']['CONCLUSION']['0']['#']);
        $webquestscorm->credits = backup_todb($info['MOD']['#']['CREDITS']['0']['#']);
        $webquestscorm->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
        //We have to recode the grade field if it is <0 (scale)
        if ($webquestscorm->grade < 0) {
            $scale = backup_getid($restore->backup_unique_code, "scale", abs($webquestscorm->grade));
            if ($scale) {
                $webquestscorm->grade = -$scale->new_id;
            }
        }
        //The structure is equal to the db, so insert the webquestscorm
        $newid = insert_record("webquestscorm", $webquestscorm);
        //Do some output
        if (!defined('RESTORE_SILENTLY')) {
            echo "<li>" . get_string("modulename", "webquestscorm") . " \"" . format_string(stripslashes($webquestscorm->name), true) . "\"</li>";
        }
        backup_flush(300);
        if ($newid) {
            //We have the newid, update backup_ids
            backup_putid($restore->backup_unique_code, $mod->modtype, $mod->id, $newid);
            //Now check if want to restore user data and do it.
            if (restore_userdata_selected($restore, 'webquestscorm', $mod->id)) {
                //Restore assignmet_submissions
                $status = webquestscorm_submissions_restore_mods($mod->id, $newid, $info, $restore) && $status;
            }
        } else {
            $status = false;
        }
    } else {
        $status = false;
    }
    return $status;
}
Esempio n. 26
0
function hotpot_restore_mods($mod, $restore)
{
    //This function restores a single hotpot activity
    // This function is called by "restore_create_modules" (in "backup/restorelib.php")
    // which is called by "backup/restore_execute.html" (included by "backup/restore.php")
    // $mod is an object
    //     id           : id field in 'modtype' table
    //     modtype      : 'hotpot'
    // $restore is an object
    //     backup_unique_code : xxxxxxxxxx
    //     file         : '/full/path/to/backupfile.zip'
    //     mods         : an array of $modinfo's (see below)
    //     restoreto    : 0=existing course (replace), 1=existing course (append), 2=new course
    //     users        : 0=all, 1=course, 2=none
    //     logs         : 0=no, 1=yes
    //     user_files   : 0=no, 1=yes
    //     course_files : 0=no, 1=yes
    //     course_id    : id of course into which data is to be restored
    //     deleting     : true if 'restoreto'==0, otherwise false
    //     original_wwwroot : 'http://your.server.com/moodle'
    // $modinfo is an array
    //    'modname'    : array( 'restore'=> 0=no 1=yes, 'userinfo' => 0=no 1=yes)
    global $CFG;
    $status = true;
    // get course module data this hotpot activity
    $data = backup_getid($restore->backup_unique_code, 'hotpot', $mod->id);
    if ($data) {
        // $data is an object
        //    backup_code => xxxxxxxxxx,
        //    table_name  => 'hotpot',
        //    old_id      => xxx,
        //    new_id      => NULL,
        //    info        => xml tree array of info backed up for this hotpot activity
        $xml =& $data->info['MOD']['#'];
        $table = 'hotpot';
        $foreign_keys = array('course' => $restore->course_id);
        $more_restore = '';
        // print a message after each hotpot is backed up
        if (!defined('RESTORE_SILENTLY')) {
            $more_restore .= 'print "<li>".get_string("modulename", "hotpot")." &quot;".format_string(stripslashes($record->name),true)."&quot;</li>";';
        }
        $more_restore .= 'backup_flush(300);';
        if (function_exists('restore_userdata_selected')) {
            // Moodle >= 1.6
            $restore_userdata_selected = restore_userdata_selected($restore, 'hotpot', $mod->id);
        } else {
            // Moodle <= 1.5
            $restore_userdata_selected = $restore->mods['hotpot']->userinfo;
        }
        if ($restore_userdata_selected) {
            $has_details = false;
            if (isset($xml["ATTEMPT_DATA"]["0"]["#"]["ATTEMPT"]["0"]["#"]["DETAILS"]["0"]["#"])) {
                $details = trim($xml["ATTEMPT_DATA"]["0"]["#"]["ATTEMPT"]["0"]["#"]["DETAILS"]["0"]["#"]);
                if ($details != '' && $details != '<?xml version="1.0"?><hpjsresult><fields></fields></hpjsresult>') {
                    $has_details = true;
                }
            }
            if ($has_details && empty($xml["STRING_DATA"]) && empty($xml["QUESTION_DATA"])) {
                // HotPot v2.0.x (regenerate questions, responses and strings from attempt details)
                $more_restore .= '$status = hotpot_restore_attempts($restore, $status, $xml, $record, true);';
            } else {
                // HotPot v2.1+
                $more_restore .= '$status = hotpot_restore_strings($restore, $status, $xml, $record);';
                $more_restore .= '$status = hotpot_restore_questions($restore, $status, $xml, $record);';
                $more_restore .= '$status = hotpot_restore_attempts($restore, $status, $xml, $record);';
            }
        }
        // if necessary, adjust HotPot date/time fields and write to restorelog
        if ($restore->course_startdateoffset) {
            restore_log_date_changes('Hotpot', $restore, $xml, array('TIMEOPEN', 'TIMECLOSE', 'TIMECREATED', 'TIMEMODIFIED'));
        }
        $status = hotpot_restore_records($restore, $status, $xml, $table, $foreign_keys, $more_restore);
    }
    return $status;
}
Esempio n. 27
0
function workshop_restore_mods($mod, $restore)
{
    global $CFG;
    $status = true;
    //Get record from backup_ids
    $data = backup_getid($restore->backup_unique_code, $mod->modtype, $mod->id);
    if ($data) {
        //Now get completed xmlized object
        $info = $data->info;
        //if necessary, write to restorelog and adjust date/time fields
        if ($restore->course_startdateoffset) {
            restore_log_date_changes('Workshop', $restore, $info['MOD']['#'], array('SUBMISSIONSTART', 'ASSESSMENTSTART', 'SUBMISSIONEND', 'ASSESSMENTEND', 'RELEASEGRADES'));
        }
        //traverse_xmlize($info);                                                                     //Debug
        //print_object ($GLOBALS['traverse_array']);                                                  //Debug
        //$GLOBALS['traverse_array']="";                                                              //Debug
        //Now, build the WORKSHOP record structure
        $workshop->course = $restore->course_id;
        $workshop->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
        $workshop->description = backup_todb($info['MOD']['#']['DESCRIPTION']['0']['#']);
        $workshop->wtype = backup_todb($info['MOD']['#']['WTYPE']['0']['#']);
        $workshop->nelements = backup_todb($info['MOD']['#']['NELEMENTS']['0']['#']);
        $workshop->nattachments = backup_todb($info['MOD']['#']['NATTACHMENTS']['0']['#']);
        $workshop->phase = backup_todb($info['MOD']['#']['PHASE']['0']['#']);
        $workshop->format = backup_todb($info['MOD']['#']['FORMAT']['0']['#']);
        $workshop->gradingstrategy = backup_todb($info['MOD']['#']['GRADINGSTRATEGY']['0']['#']);
        $workshop->resubmit = backup_todb($info['MOD']['#']['RESUBMIT']['0']['#']);
        $workshop->agreeassessments = backup_todb($info['MOD']['#']['AGREEASSESSMENTS']['0']['#']);
        $workshop->hidegrades = backup_todb($info['MOD']['#']['HIDEGRADES']['0']['#']);
        $workshop->anonymous = backup_todb($info['MOD']['#']['ANONYMOUS']['0']['#']);
        $workshop->includeself = backup_todb($info['MOD']['#']['INCLUDESELF']['0']['#']);
        $workshop->maxbytes = backup_todb($info['MOD']['#']['MAXBYTES']['0']['#']);
        $workshop->submissionstart = backup_todb($info['MOD']['#']['SUBMISSIONSTART']['0']['#']);
        $workshop->assessmentstart = backup_todb($info['MOD']['#']['ASSESSMENTSTART']['0']['#']);
        $workshop->deadline = backup_todb($info['MOD']['#']['DEADLINE']['0']['#']);
        $workshop->submissionend = backup_todb($info['MOD']['#']['SUBMISSIONEND']['0']['#']);
        $workshop->assessmentend = backup_todb($info['MOD']['#']['ASSESSMENTEND']['0']['#']);
        $workshop->releasegrades = backup_todb($info['MOD']['#']['RELEASEGRADES']['0']['#']);
        $workshop->grade = backup_todb($info['MOD']['#']['GRADE']['0']['#']);
        $workshop->gradinggrade = backup_todb($info['MOD']['#']['GRADINGGRADE']['0']['#']);
        $workshop->ntassessments = backup_todb($info['MOD']['#']['NTASSESSMENTS']['0']['#']);
        $workshop->assessmentcomps = backup_todb($info['MOD']['#']['ASSESSMENTCOMPS']['0']['#']);
        $workshop->nsassessments = backup_todb($info['MOD']['#']['NSASSESSMENTS']['0']['#']);
        $workshop->overallocation = backup_todb($info['MOD']['#']['OVERALLOCATION']['0']['#']);
        $workshop->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
        $workshop->teacherweight = backup_todb($info['MOD']['#']['TEACHERWEIGHT']['0']['#']);
        $workshop->showleaguetable = backup_todb($info['MOD']['#']['SHOWLEAGUETABLE']['0']['#']);
        $workshop->usepassword = backup_todb($info['MOD']['#']['USEPASSWORD']['0']['#']);
        $workshop->password = backup_todb($info['MOD']['#']['PASSWORD']['0']['#']);
        //If we have retrieved workshop->phase, it's a pre 1.5 backup, so we have to do
        //some conversions before inserting to DB. Upwards compatibility :-)
        if (isset($info['MOD']['#']['PHASE']['0']['#'])) {
            //It's a pre-15 backup file
            //Adjust the wtype field (mimetised from the upgrade script)
            $workshop->wtype = 0;
            if ($workshop->includeself || $workshop->ntassessments) {
                $workshop->wtype = 1;
                // 3 phases with grading grades
            } else {
                if ($workshop->nsassessments) {
                    $workshop->wtype = 2;
                    // 5 phases with grading grades
                }
            }
            //Now, adjust phases time limits (mimetised from the upgrade script too)
            $early = 0;
            $late = 0;
            $now = time();
            if ($now < $workshop->deadline) {
                $late = $workshop->deadline;
            } else {
                $early = $workshop->deadline;
            }
            if ($workshop->phase > 1) {
                $workshop->submissionstart = $early;
            } else {
                $workshop->submissionstart = $late;
            }
            if ($workshop->phase > 2) {
                $workshop->assessmentstart = $early;
            } else {
                $workshop->assessmentstart = $late;
            }
            if ($workshop->phase > 3) {
                $workshop->submissionend = $early;
            } else {
                $workshop->submissionend = $late;
            }
            if ($workshop->phase > 4) {
                $workshop->assessmentend = $early;
            } else {
                $workshop->assessmentend = $late;
            }
            if ($workshop->phase > 5) {
                $workshop->releasegrades = $now;
            } else {
                $workshop->releasegrades = $now + 4 * 7 * 24 * 60 * 60;
                //Grades will be available in 4 weeks
            }
        }
        //The structure is equal to the db, so insert the workshop
        $newid = insert_record("workshop", $workshop);
        //Do some output
        if (!defined('RESTORE_SILENTLY')) {
            echo "<li>" . get_string("modulename", "workshop") . " \"" . format_string(stripslashes($workshop->name), true) . "\"</li>";
        }
        backup_flush(300);
        if ($newid) {
            //We have the newid, update backup_ids
            backup_putid($restore->backup_unique_code, $mod->modtype, $mod->id, $newid);
            //We have to restore the workshop_elements table now (course level table)
            $status = workshop_elements_restore_mods($newid, $info, $restore);
            //Now check if want to restore user data and do it.
            if (restore_userdata_selected($restore, 'workshop', $mod->id)) {
                //Restore workshop_submissions
                $status = workshop_submissions_restore_mods($mod->id, $newid, $info, $restore);
            }
        } else {
            $status = false;
        }
    } else {
        $status = false;
    }
    return $status;
}
Esempio n. 28
0
function data_restore_mods($mod, $restore)
{
    global $CFG;
    $status = true;
    $data = backup_getid($restore->backup_unique_code, $mod->modtype, $mod->id);
    if ($data) {
        //Now get completed xmlized object
        $info = $data->info;
        // if necessary, write to restorelog and adjust date/time fields
        if ($restore->course_startdateoffset) {
            restore_log_date_changes('Database', $restore, $info['MOD']['#'], array('TIMEAVAILABLEFROM', 'TIMEAVAILABLETO', 'TIMEVIEWFROM', 'TIMEVIEWTO'));
        }
        //traverse_xmlize($info);                                                                     //Debug
        //print_object ($GLOBALS['traverse_array']);                                                  //Debug
        //$GLOBALS['traverse_array']="";                                                              //Debug
        $database->course = $restore->course_id;
        $database->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
        $database->intro = backup_todb($info['MOD']['#']['INTRO']['0']['#']);
        // Only relevant for restoring backups from 1.6 in a 1.7 install.
        if (isset($info['MOD']['#']['RATINGS']['0']['#'])) {
            $database->ratings = backup_todb($info['MOD']['#']['RATINGS']['0']['#']);
        }
        $database->comments = backup_todb($info['MOD']['#']['COMMENTS']['0']['#']);
        $database->timeavailablefrom = backup_todb($info['MOD']['#']['TIMEAVAILABLEFROM']['0']['#']);
        $database->timeavailableto = backup_todb($info['MOD']['#']['TIMEAVAILABLETO']['0']['#']);
        $database->timeviewfrom = backup_todb($info['MOD']['#']['TIMEVIEWFROM']['0']['#']);
        $database->timeviewto = backup_todb($info['MOD']['#']['TIMEVIEWTO']['0']['#']);
        // Only relevant for restoring backups from 1.6 in a 1.7 install.
        if (isset($info['MOD']['#']['PARTICIPANTS']['0']['#'])) {
            $database->participants = backup_todb($info['MOD']['#']['PARTICIPANTS']['0']['#']);
        }
        $database->requiredentries = backup_todb($info['MOD']['#']['REQUIREDENTRIES']['0']['#']);
        $database->requiredentriestoview = backup_todb($info['MOD']['#']['REQUIREDENTRIESTOVIEW']['0']['#']);
        $database->maxentries = backup_todb($info['MOD']['#']['MAXENTRIES']['0']['#']);
        $database->rssarticles = backup_todb($info['MOD']['#']['RSSARTICLES']['0']['#']);
        $database->singletemplate = backup_todb($info['MOD']['#']['SINGLETEMPLATE']['0']['#']);
        $database->listtemplate = backup_todb($info['MOD']['#']['LISTTEMPLATE']['0']['#']);
        $database->listtemplateheader = backup_todb($info['MOD']['#']['LISTTEMPLATEHEADER']['0']['#']);
        $database->listtemplatefooter = backup_todb($info['MOD']['#']['LISTTEMPLATEFOOTER']['0']['#']);
        $database->addtemplate = backup_todb($info['MOD']['#']['ADDTEMPLATE']['0']['#']);
        $database->rsstemplate = backup_todb($info['MOD']['#']['RSSTEMPLATE']['0']['#']);
        $database->rsstitletemplate = backup_todb($info['MOD']['#']['RSSTITLETEMPLATE']['0']['#']);
        $database->csstemplate = backup_todb($info['MOD']['#']['CSSTEMPLATE']['0']['#']);
        $database->jstemplate = backup_todb($info['MOD']['#']['JSTEMPLATE']['0']['#']);
        $database->asearchtemplate = backup_todb($info['MOD']['#']['ASEARCHTEMPLATE']['0']['#']);
        $database->approval = backup_todb($info['MOD']['#']['APPROVAL']['0']['#']);
        $database->scale = backup_todb($info['MOD']['#']['SCALE']['0']['#']);
        $database->assessed = backup_todb($info['MOD']['#']['ASSESSED']['0']['#']);
        // Only relevant for restoring backups from 1.6 in a 1.7 install.
        if (isset($info['MOD']['#']['ASSESSPUBLIC']['0']['#'])) {
            $database->assesspublic = backup_todb($info['MOD']['#']['ASSESSPUBLIC']['0']['#']);
        }
        $database->defaultsort = backup_todb($info['MOD']['#']['DEFAULTSORT']['0']['#']);
        $database->defaultsortdir = backup_todb($info['MOD']['#']['DEFAULTSORTDIR']['0']['#']);
        $database->editany = backup_todb($info['MOD']['#']['EDITANY']['0']['#']);
        $database->notification = backup_todb($info['MOD']['#']['NOTIFICATION']['0']['#']);
        // We have to recode the scale field if it's <0 (positive is a grade, not a scale)
        if ($database->scale < 0) {
            $scale = backup_getid($restore->backup_unique_code, 'scale', abs($database->scale));
            if ($scale) {
                $database->scale = -$scale->new_id;
            }
        }
        $newid = insert_record('data', $database);
        //Do some output
        if (!defined('RESTORE_SILENTLY')) {
            echo "<li>" . get_string("modulename", "data") . " \"" . format_string(stripslashes($database->name), true) . "\"</li>";
        }
        if ($newid) {
            //We have the newid, update backup_ids
            backup_putid($restore->backup_unique_code, $mod->modtype, $mod->id, $newid);
            //Now check if want to restore user data and do it.
            if (function_exists('restore_userdata_selected')) {
                // Moodle 1.6
                $restore_userdata_selected = restore_userdata_selected($restore, 'data', $mod->id);
            } else {
                // Moodle 1.5
                $restore_userdata_selected = $restore->mods['data']->userinfo;
            }
            global $fieldids;
            //Restore data_fields first!!! need to hold an array of [oldid]=>newid due to double dependencies
            $status = $status and data_fields_restore_mods($mod->id, $newid, $info, $restore);
            // now use the new field in the defaultsort
            $newdefaultsort = empty($fieldids[$database->defaultsort]) ? 0 : $fieldids[$database->defaultsort];
            set_field('data', 'defaultsort', $newdefaultsort, 'id', $newid);
            if ($restore_userdata_selected) {
                $status = $status and data_records_restore_mods($mod->id, $newid, $info, $restore);
            }
            // If the backup contained $data->participants, $data->assesspublic
            // and $data->groupmode, we need to convert the data to use Roles.
            // It means the backup was made pre Moodle 1.7. We check the
            // backup_version to make sure.
            if (isset($database->participants) && isset($database->assesspublic)) {
                if (!($teacherroles = get_roles_with_capability('moodle/legacy:teacher', CAP_ALLOW))) {
                    notice('Default teacher role was not found. Roles and permissions ' . 'for your database modules will have to be manually set.');
                }
                if (!($studentroles = get_roles_with_capability('moodle/legacy:student', CAP_ALLOW))) {
                    notice('Default student role was not found. Roles and permissions ' . 'for all your database modules will have to be manually set.');
                }
                if (!($guestroles = get_roles_with_capability('moodle/legacy:guest', CAP_ALLOW))) {
                    notice('Default guest role was not found. Roles and permissions ' . 'for all your database modules will have to be manually set.');
                }
                require_once $CFG->dirroot . '/mod/data/lib.php';
                data_convert_to_roles($database, $teacherroles, $studentroles, $restore->mods['data']->instances[$mod->id]->restored_as_course_module);
            }
        } else {
            $status = false;
        }
    } else {
        $status = false;
    }
    return $status;
}
Esempio n. 29
0
function dimdim_restore_mods($mod, $restore)
{
    global $CFG;
    $status = true;
    //Get record from backup_ids
    $data = backup_getid($restore->backup_unique_code, $mod->modtype, $mod->id);
    if ($data) {
        //Now get completed xmlized object
        $info = $data->info;
        //traverse_xmlize($info);                                                                     //Debug
        //print_object ($GLOBALS['traverse_array']);                                                  //Debug
        //$GLOBALS['traverse_array']="";                                                              //Debug
        // if necessary, write to restorelog and adjust date/time fields
        if ($restore->course_startdateoffset) {
            restore_log_date_changes('dimdim', $restore, $info['MOD']['#'], array('dimdimTIME'));
        }
        //Now, build the dimdim record structure
        $dimdim->course = $restore->course_id;
        $dimdim->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
        $dimdim->intro = backup_todb($info['MOD']['#']['INTRO']['0']['#']);
        $dimdim->keepdays = backup_todb($info['MOD']['#']['KEEPDAYS']['0']['#']);
        $dimdim->studentlogs = backup_todb($info['MOD']['#']['STUDENTLOGS']['0']['#']);
        $dimdim->dimdimtime = backup_todb($info['MOD']['#']['dimdimTIME']['0']['#']);
        $dimdim->schedule = backup_todb($info['MOD']['#']['SCHEDULE']['0']['#']);
        $dimdim->confkey = backup_todb($info['MOD']['#']['confkey']['0']['#']);
        $dimdim->emailuser = backup_todb($info['MOD']['#']['emailuser']['0']['#']);
        $dimdim->displayname = backup_todb($info['MOD']['#']['displayname']['0']['#']);
        $dimdim->startnow = backup_todb($info['MOD']['#']['startnow']['0']['#']);
        $dimdim->attendees = backup_todb($info['MOD']['#']['attendees']['0']['#']);
        $dimdim->timezone = backup_todb($info['MOD']['#']['timezone']['0']['#']);
        $dimdim->timestr = backup_todb($info['MOD']['#']['timestr']['0']['#']);
        $dimdim->lobby = backup_todb($info['MOD']['#']['lobby']['0']['#']);
        $dimdim->networkprofile = backup_todb($info['MOD']['#']['networkprofile']['0']['#']);
        $dimdim->meetinghours = backup_todb($info['MOD']['#']['meetinghours']['0']['#']);
        $dimdim->meetingminutes = backup_todb($info['MOD']['#']['meetingminutes']['0']['#']);
        $dimdim->maxparticipants = backup_todb($info['MOD']['#']['maxparticipants']['0']['#']);
        $dimdim->timemodified = backup_todb($info['MOD']['#']['timemodified']['0']['#']);
        $dimdim->audiovideosettings = backup_todb($info['MOD']['#']['audiovideosettings']['0']['#']);
        $dimdim->maxmikes = backup_todb($info['MOD']['#']['maxmikes']['0']['#']);
        //The structure is equal to the db, so insert the dimdim
        $newid = insert_record("dimdim", $dimdim);
        //Do some output
        if (!defined('RESTORE_SILENTLY')) {
            echo "<li>" . get_string("modulename", "dimdim") . " \"" . format_string(stripslashes($dimdim->name), true) . "\"</li>";
        }
        backup_flush(300);
        if ($newid) {
            //We have the newid, update backup_ids
            backup_putid($restore->backup_unique_code, $mod->modtype, $mod->id, $newid);
            //Now check if want to restore user data and do it.
            if (restore_userdata_selected($restore, 'dimdim', $mod->id)) {
                //Restore dimdim_messages
                $status = false;
            }
        } else {
            $status = false;
        }
    } else {
        $status = false;
    }
    return $status;
}