Ejemplo n.º 1
0
function backup_poodllpairwork_files_instance($bf, $preferences, $instanceid)
{
    global $CFG;
    $status = true;
    //First we check to moddata exists and create it as necessary
    //in temp/backup/$backup_code  dir
    $status = check_and_create_moddata_dir($preferences->backup_unique_code);
    $status = check_dir_exists($CFG->dataroot . "/temp/backup/" . $preferences->backup_unique_code . "/moddata/poodllpairwork/", true);
    //Now copy the poodllpairwork dir
    if ($status) {
        //Only if it exists !! Thanks to Daniel Miksik.
        if (is_dir($CFG->dataroot . "/" . $preferences->backup_course . "/" . $CFG->moddata . "/poodllpairwork/" . $instanceid)) {
            $status = backup_copy_file($CFG->dataroot . "/" . $preferences->backup_course . "/" . $CFG->moddata . "/poodllpairwork/" . $instanceid, $CFG->dataroot . "/temp/backup/" . $preferences->backup_unique_code . "/moddata/poodllpairwork/" . $instanceid);
        }
    }
    return $status;
}
Ejemplo n.º 2
0
function backup_nanogong_message($bf, $preferences, $nanogong)
{
    global $CFG;
    $status = true;
    //First we check to moddata exists and create it as necessary
    //in temp/backup/$backup_code  dir
    $status = check_and_create_moddata_dir($preferences->backup_unique_code);
    $status = check_dir_exists($CFG->dataroot . "/temp/backup/" . $preferences->backup_unique_code . "/moddata/nanogong/", true);
    $nanogong_message = get_records("nanogong_message", "nanogongid", $nanogong, "id");
    //If there is a message
    if ($nanogong_message) {
        //Write start tag
        $status = fwrite($bf, start_tag("MESSAGES", 4, true));
        //Iterate over each message
        foreach ($nanogong_message as $message) {
            //Sound filename
            $fn = array_pop(explode('/', $message->path));
            //Start message
            $status = fwrite($bf, start_tag("MESSAGE", 5, true));
            //Print message data
            fwrite($bf, full_tag("ID", 6, false, $message->id));
            fwrite($bf, full_tag("USERID", 6, false, $message->userid));
            fwrite($bf, full_tag("GROUPID", 6, false, $message->groupid));
            fwrite($bf, full_tag("TITLE", 6, false, $message->title));
            fwrite($bf, full_tag("MESSAGE", 6, false, $message->message));
            fwrite($bf, full_tag("PATH", 6, false, $fn));
            fwrite($bf, full_tag("COMMENTS", 6, false, $message->comments));
            fwrite($bf, full_tag("COMMENTEDBY", 6, false, $message->commentedby));
            fwrite($bf, full_tag("SCORE", 6, false, $message->score));
            fwrite($bf, full_tag("TIMESTAMP", 6, false, $message->timestamp));
            fwrite($bf, full_tag("TIMEEDITED", 6, false, $message->timeedited));
            fwrite($bf, full_tag("LOCKED", 6, false, $message->locked));
            //End submission
            $status = fwrite($bf, end_tag("MESSAGE", 5, true));
            //Copy the file
            if (is_dir($CFG->dataroot . "/" . $preferences->backup_course . "/" . $CFG->moddata . "/nanogong/" . $message->userid)) {
                $status = check_dir_exists($CFG->dataroot . "/temp/backup/" . $preferences->backup_unique_code . "/moddata/nanogong/" . $message->userid, true);
                $status = backup_copy_file($CFG->dataroot . $message->path, $CFG->dataroot . "/temp/backup/" . $preferences->backup_unique_code . "/moddata/nanogong/" . $message->userid . "/" . $fn);
            }
        }
        //Write end tag
        $status = fwrite($bf, end_tag("MESSAGES", 4, true));
    }
    return $status;
}
Ejemplo n.º 3
0
function backup_blended_files($bf, $preferences)
{
    global $CFG;
    $status = true;
    //First we check to moddata exists and create it as necessary
    //in temp/backup/$backup_code  dir
    $status = check_and_create_moddata_dir($preferences->backup_unique_code);
    //Now copy the questournament dir
    if ($status) {
        if (is_dir($CFG->dataroot . "/" . $preferences->backup_course . "/" . $CFG->moddata . "/blended")) {
            $dir = "{$CFG->dataroot}/temp/backup/{$preferences->backup_unique_code}/moddata/blended";
            check_dir_exists($dir, true);
            $status = backup_copy_file($CFG->dataroot . "/" . $preferences->backup_course . "/" . $CFG->moddata . "/blended", $CFG->dataroot . "/temp/backup/" . $preferences->backup_unique_code . "/moddata/blended");
        }
    }
    return $status;
}
Ejemplo n.º 4
0
function backup_scorm_files($bf, $preferences)
{
    global $CFG;
    $status = true;
    //First we check to moddata exists and create it as necessary
    //in temp/backup/$backup_code  dir
    $status = check_and_create_moddata_dir($preferences->backup_unique_code);
    //Now copy the scorm dir
    if ($status) {
        if (is_dir($CFG->dataroot . '/' . $preferences->backup_course . '/' . $CFG->moddata . '/scorm')) {
            $handle = opendir($CFG->dataroot . '/' . $preferences->backup_course . '/' . $CFG->moddata . '/scorm');
            while (false !== ($item = readdir($handle))) {
                if ($item != '.' && $item != '..' && is_dir($CFG->dataroot . '/' . $preferences->backup_course . '/' . $CFG->moddata . '/scorm/' . $item) && array_key_exists($item, $preferences->mods['scorm']->instances) && !empty($preferences->mods['scorm']->instances[$item]->backup)) {
                    $status = backup_copy_file($CFG->dataroot . '/' . $preferences->backup_course . '/' . $CFG->moddata . '/scorm/' . $item, $CFG->dataroot . '/temp/backup/' . $preferences->backup_unique_code . '/moddata/scorm/', $item);
                }
            }
        }
    }
    return $status;
}
function backup_imagegallery_files($bf, $preferences, $image)
{
    global $CFG;
    $status = true;
    //First we check to moddata exists and create it as necessary
    //in temp/backup/$backup_code  dir
    $status = check_and_create_moddata_dir($preferences->backup_unique_code);
    //Now we check that moddata/glossary dir exists and create it as necessary
    //in temp/backup/$backup_code/moddata dir
    $gal_dir_to = $CFG->dataroot . "/temp/backup/" . $preferences->backup_unique_code . "/" . $CFG->moddata . "/imagegallery";
    //Let's create it as necessary
    $status = check_dir_exists($gal_dir_to, true);
    // Check imagegalleryid directory.
    $gal_dir_to .= '/' . $image->galleryid;
    $status = check_dir_exists($gal_dir_to, true);
    // structure for imagegallery data directory starting from moddata:
    // moddata
    //    |
    //    |- imagegallery
    //            |
    //            |- <imagegalleryid>
    //                      |
    //                      |- non-categorized images
    //                      |- <categoryid>
    //                              |
    //                              |- categorized images.
    if (!empty($image->categoryid)) {
        // Copy categorized image under it's directory ( create directory if necessary ).
        $gal_dir_to .= '/' . $image->categoryid;
        $status = check_dir_exists($gal_dir_to, true);
        $filesource = $CFG->dataroot . $image->path;
        $filedestin = $gal_dir_to . '/' . $image->name;
        if (is_dir($gal_dir_to) && file_exists($filesource)) {
            $status = backup_copy_file($filesource, $filedestin);
        }
        // Copy thumbnail
        $filesource = $CFG->dataroot . str_replace($image->name, "thumb_" . $image->name, $image->path);
        $filedestin = $gal_dir_to . '/thumb_' . $image->name;
        if (is_dir($gal_dir_to) && file_exists($filesource)) {
            $status = backup_copy_file($filesource, $filedestin);
        }
    } else {
        // Copy uncategorized image under imagegallery id.
        $filesource = $CFG->dataroot . $image->path;
        $filedestin = $gal_dir_to . '/' . $image->name;
        if (is_dir($gal_dir_to) && file_exists($filesource)) {
            $status = backup_copy_file($filesource, $filedestin);
        }
        // Copy thumbnail
        $filesource = $CFG->dataroot . str_replace($image->name, "thumb_" . $image->name, $image->path);
        $filedestin = $gal_dir_to . '/thumb_' . $image->name;
        if (is_dir($gal_dir_to) && file_exists($filesource)) {
            $status = backup_copy_file($filesource, $filedestin);
        }
    }
    return $status;
}
Ejemplo n.º 6
0
function backup_glossary_files($bf, $preferences, $glossary, $entry)
{
    global $CFG;
    $status = true;
    //First we check to moddata exists and create it as necessary
    //in temp/backup/$backup_code  dir
    $status = check_and_create_moddata_dir($preferences->backup_unique_code);
    //Now we check that moddata/glossary dir exists and create it as necessary
    //in temp/backup/$backup_code/moddata dir
    $glo_dir_to = $CFG->dataroot . "/temp/backup/" . $preferences->backup_unique_code . "/" . $CFG->moddata . "/glossary";
    //Let's create it as necessary
    $status = check_dir_exists($glo_dir_to, true);
    //Now we check that the moddata/glossary/$glossary dir exists and create it as necessary
    //in temp/backup/$backup_code/moddata/glossary
    $status = check_dir_exists($glo_dir_to . "/" . $glossary, true);
    //Now copy the moddata/glossary/$glossary/$entry to
    //temp/backup/$backup_code/moddata/glossary/$glossary/$entry
    if ($status) {
        //Calculate moddata/glossary dir
        $glo_dir_from = $CFG->dataroot . "/" . $preferences->backup_course . "/" . $CFG->moddata . "/glossary";
        //Only if it exists !!
        if (is_dir($glo_dir_from . "/" . $glossary . "/" . $entry)) {
            $status = backup_copy_file($glo_dir_from . "/" . $glossary . "/" . $entry, $glo_dir_to . "/" . $glossary . "/" . $entry);
        }
    }
    return $status;
}
function flv_backup_files($bf, $preferences, $flv)
{
    global $CFG;
    $status = true;
    if (!file_exists($CFG->dataroot . '/' . $preferences->backup_course . '/' . $flv->flvfile)) {
        return true;
        // doesn't exist but we don't want to halt the entire process so still return true.
    }
    $status = $status && check_and_create_course_files_dir($preferences->backup_unique_code);
    // if this is somewhere deeply nested we need to do all the structure stuff first.....
    $bits = explode('/', $flv->flvfile);
    $newbit = '';
    for ($i = 0; $i < count($bits) - 1; $i++) {
        $newbit .= $bits[$i] . '/';
        $status = $status && check_dir_exists($CFG->dataroot . '/temp/backup/' . $preferences->backup_unique_code . '/course_files/' . $newbit, true);
    }
    if ($flv->flvfile === '') {
        $status = $status && backup_copy_course_files($preferences);
        // copy while ignoring backupdata and moddata!!!
    } else {
        if (strpos($flv->flvfile, 'backupdata') === 0 or strpos($flv->flvfile, $CFG->moddata) === 0) {
            // no copying - these directories must not be shared anyway!
        } else {
            $status = $status && backup_copy_file($CFG->dataroot . "/" . $preferences->backup_course . "/" . $flv->flvfile, $CFG->dataroot . "/temp/backup/" . $preferences->backup_unique_code . "/course_files/" . $flv->flvfile);
        }
    }
    // now, just in case we check moddata ( going forwards, flvs should use this )
    $status = $status && check_and_create_moddata_dir($preferences->backup_unique_code);
    $status = $status && check_dir_exists($CFG->dataroot . "/temp/backup/" . $preferences->backup_unique_code . "/" . $CFG->moddata . "/flv/", true);
    if ($status) {
        //Only if it exists !! Thanks to Daniel Miksik.
        $instanceid = $flv->id;
        if (is_dir($CFG->dataroot . "/" . $preferences->backup_course . "/" . $CFG->moddata . "/flv/" . $instanceid)) {
            $status = backup_copy_file($CFG->dataroot . "/" . $preferences->backup_course . "/" . $CFG->moddata . "/flv/" . $instanceid, $CFG->dataroot . "/temp/backup/" . $preferences->backup_unique_code . "/moddata/flv/" . $instanceid);
        }
    }
    return $status;
}
Ejemplo n.º 8
0
function backup_wiki_files($bf, $preferences)
{
    global $CFG;
    $status = true;
    //First we check to moddata exists and create it as necessary
    //in temp/backup/$backup_code  dir
    $status = check_and_create_moddata_dir($preferences->backup_unique_code);
    //Now copy the forum dir
    if ($status) {
        //Only if it exists !! Thanks to Daniel Miksik.
        if (is_dir($CFG->dataroot . "/" . $preferences->backup_course . "/" . $CFG->moddata . "/wiki")) {
            $handle = opendir($CFG->dataroot . "/" . $preferences->backup_course . "/" . $CFG->moddata . "/wiki");
            while (false !== ($item = readdir($handle))) {
                if ($item != '.' && $item != '..' && is_dir($CFG->dataroot . "/" . $preferences->backup_course . "/" . $CFG->moddata . "/wiki/" . $item) && array_key_exists($item, $preferences->mods['wiki']->instances) && !empty($preferences->mods['wiki']->instances[$item]->backup)) {
                    $status = backup_copy_file($CFG->dataroot . "/" . $preferences->backup_course . "/" . $CFG->moddata . "/wiki/" . $item, $CFG->dataroot . "/temp/backup/" . $preferences->backup_unique_code . "/moddata/wiki/", $item);
                }
            }
        }
    }
    return $status;
}
function backup_turnitintool_files_instance($bf, $preferences, $instanceid)
{
    global $CFG;
    $status = true;
    $status = check_and_create_moddata_dir($preferences->backup_unique_code);
    $status = check_dir_exists($CFG->dataroot . "/temp/backup/" . $preferences->backup_unique_code . "/moddata/turnitintool/", true);
    if ($status) {
        if (is_dir($CFG->dataroot . "/" . $preferences->backup_course . "/" . $CFG->moddata . "/turnitintool/" . $instanceid)) {
            $status = backup_copy_file($CFG->dataroot . "/" . $preferences->backup_course . "/" . $CFG->moddata . "/turnitintool/" . $instanceid, $CFG->dataroot . "/temp/backup/" . $preferences->backup_unique_code . "/moddata/turnitintool/" . $instanceid);
        }
    }
    return $status;
}
//Backup podcast files because we've selected to backup user info
//and files are user info's level
function backup_podcast_files_instance($bf, $preferences, $instanceid)
{
    global $CFG;
    $status = true;
    // MEDIA
    // in temp/backup/$backup_code  dir
    $status = check_and_create_moddata_dir($preferences->backup_unique_code);
    $status = check_dir_exists($CFG->dataroot . "/temp/backup/" . $preferences->backup_unique_code . "/moddata/podcast/", true);
    if ($status) {
        // Copie des fichiers multim�dia
        if (is_dir($CFG->dirroot . "/mod/podcast/media/" . $preferences->backup_course . "/" . $instanceid)) {
            $status = backup_copy_file($CFG->dirroot . "/mod/podcast/media/" . $preferences->backup_course . "/" . $instanceid, $CFG->dataroot . "/temp/backup/" . $preferences->backup_unique_code . "/moddata/podcast/media/" . $instanceid);
        }
    }
    // XML
    // in temp/backup/$backup_code  dir
    $status = check_and_create_moddata_dir($preferences->backup_unique_code);
    $status = check_dir_exists($CFG->dataroot . "/temp/backup/" . $preferences->backup_unique_code . "/moddata/podcast/", true);
    if ($status) {
        // Copie des fichiers rss
        if (is_dir($CFG->dirroot . "/mod/podcast/media/" . $preferences->backup_course . "/" . $instanceid)) {
            $status = backup_copy_file($CFG->dirroot . "/mod/podcast/publication/" . $preferences->backup_course, $CFG->dataroot . "/temp/backup/" . $preferences->backup_unique_code . "/moddata/podcast/publication/");
        }
    }
Ejemplo n.º 11
0
function backup_exercise_student_files($bf, $preferences, $exerciseid)
{
    global $CFG;
    $status = true;
    //First we check to moddata exists and create it as necessary
    //in temp/backup/$backup_code  dir
    $status = check_and_create_moddata_dir($preferences->backup_unique_code);
    if ($status) {
        //Now copy the submission dirs
        if ($submissions = get_records_select("exercise_submissions", "exerciseid = {$exerciseid}\n                        AND isexercise = 0")) {
            foreach ($submissions as $submission) {
                //Only if it exists !! Thanks to Daniel Miksik.
                if (is_dir("{$CFG->dataroot}/{$preferences->backup_course}/{$CFG->moddata}/exercise/{$submission->id}")) {
                    $status = backup_copy_file("{$CFG->dataroot}/{$preferences->backup_course}/{$CFG->moddata}/exercise/{$submission->id}", "{$CFG->dataroot}/temp/backup/{$preferences->backup_unique_code}/moddata/exercise/{$submission->id}");
                }
            }
        }
    }
    return $status;
}
function backup_webquest_files_instance($bf, $preferences, $webquest)
{
    global $CFG;
    $status = true;
    //First we check to moddata exists and create it as necessary
    //in temp/backup/$backup_code  dir
    $webquest_submissions = get_records("webquest_submissions", "webquestid", $webquest, "id");
    $status = check_and_create_moddata_dir($preferences->backup_unique_code);
    $status = check_dir_exists($CFG->dataroot . "/temp/backup/" . $preferences->backup_unique_code . "/moddata/webquest/", true);
    if ($status and $webquest_submissions) {
        foreach ($webquest_submissions as $submission) {
            if (is_dir($CFG->dataroot . "/" . $preferences->backup_course . "/" . $CFG->moddata . "/webquest/" . $submission->id)) {
                $status = backup_copy_file($CFG->dataroot . "/" . $preferences->backup_course . "/" . $CFG->moddata . "/webquest/" . $submission->id, $CFG->dataroot . "/temp/backup/" . $preferences->backup_unique_code . "/moddata/webquest/" . $submission->id);
            }
        }
    }
    return $status;
}
function backup_netpublish_files($bf, $preferences)
{
    global $CFG;
    $status = true;
    $files = get_records("netpublish_images", "course", $preferences->backup_course, "id");
    if ($files) {
        $status = fwrite($bf, start_tag("NETPUBLISHFILES", 4, true));
        foreach ($files as $file) {
            $status = fwrite($bf, start_tag("FILE", 5, true));
            fwrite($bf, full_tag("ID", 6, false, $file->id));
            fwrite($bf, full_tag("COURSE", 6, false, $file->course));
            fwrite($bf, full_tag("NAME", 6, false, $file->name));
            fwrite($bf, full_tag("PATH", 6, false, $file->path));
            fwrite($bf, full_tag("MIMETYPE", 6, false, $file->mimetype));
            fwrite($bf, full_tag("SIZE", 6, false, $file->size));
            fwrite($bf, full_tag("WIDTH", 6, false, $file->width));
            fwrite($bf, full_tag("HEIGHT", 6, false, $file->height));
            fwrite($bf, full_tag("TIMEMODIFIED", 6, false, $file->timemodified));
            fwrite($bf, full_tag("OWNER", 6, false, $file->owner));
            fwrite($bf, full_tag("DIR", 6, false, $file->dir));
            $status = fwrite($bf, end_tag("FILE", 5, true));
        }
        $status = fwrite($bf, end_tag("NETPUBLISHFILES", 4, true));
    }
    //First we check to moddata exists and create it as necessary
    //in temp/backup/$backup_code  dir
    $status = check_and_create_moddata_dir($preferences->backup_unique_code);
    //Now copy the forum dir
    if ($status) {
        //Only if it exists !! Thanks to Daniel Miksik.
        if (is_dir($CFG->dataroot . "/netpublish_images")) {
            $status = backup_copy_file($CFG->dataroot . "/netpublish_images", $CFG->dataroot . "/temp/backup/" . $preferences->backup_unique_code . "/moddata/netpublish_images");
        }
    }
    return $status;
}