function wiki_insert_page_from_wiki($wikipage, $dfwikiid, $mode, $course, $name, $oldwikiid, $groupid)
{
    global $CFG;
    //search for the old wiki cm->id
    $modul = get_record("modules", "name", 'wiki');
    $coursemodule = get_record_sql('SELECT *
                    FROM ' . $CFG->prefix . 'course_modules
                    WHERE module=' . $modul->id . ' AND instance=' . $dfwikiid);
    $page->pagename = restore_decode_absolute_links(addslashes($wikipage->pagename));
    $page->version = $wikipage->version;
    $page->content = wiki_treat_content(restore_decode_absolute_links(addslashes($wikipage->content)), $oldwikiid);
    $page->author = wiki_get_username($wikipage->author);
    $page->created = $wikipage->created;
    $page->lastmodified = $wikipage->lastmodified;
    $pagerefs = str_replace("\n", "|", restore_decode_absolute_links(addslashes($wikipage->refs)));
    $page_refs = str_replace("||", "", $pagerefs);
    $page->refs = wiki_treat_internal_ref($page_refs);
    $page->hits = $wikipage->hits;
    $page->editable = '1';
    $page->dfwiki = $dfwikiid;
    switch ($mode) {
        case '0':
            $page->editor = 'ewiki';
            break;
        case '1':
            $page->editor = 'ewiki';
            break;
        case '2':
            $page->editor = 'htmleditor';
            break;
        default:
            break;
    }
    $page->groupid = $groupid;
    if ($page->content != '') {
        if (!insert_record('wiki_pages', addslashes($page))) {
        }
        backup_flush(300);
    }
}
function wiki_read_xml_ewiki($data)
{
    if (isset($data['ENTRIES']['0']['#']['ENTRY'])) {
        $htmlmode = $data['HTMLMODE']['0']['#'];
        $dataentries = $data['ENTRIES']['0']['#']['ENTRY'];
        $i = 0;
        foreach ($dataentries as $dataentry) {
            $groupid = $dataentry['#']['GROUPID']['0']['#'];
            foreach ($dataentry as $datapages) {
                $datapage = $datapages['PAGES']['0']['#']['PAGE'];
                foreach ($datapage as $ewikipage) {
                    $wikipages['importfrombackup'][$i]['id'] = $ewikipage['#']['ID']['0']['#'];
                    $wikipages['importfrombackup'][$i]['pagename'] = $ewikipage['#']['PAGENAME']['0']['#'];
                    $wikipages['importfrombackup'][$i]['version'] = $ewikipage['#']['VERSION']['0']['#'];
                    $wikipages['importfrombackup'][$i]['content'] = restore_decode_absolute_links(addslashes(wiki_treat_content($ewikipage['#']['CONTENT']['0']['#'])));
                    $wikipages['importfrombackup'][$i]['version'] = $ewikipage['#']['VERSION']['0']['#'];
                    $pagerefs = restore_decode_absolute_links(addslashes($ewikipage['#']['REFS']['0']['#']));
                    $pagerefs = str_replace("\$@LINEFEED@\$", "|", $pagerefs);
                    $pagerefs = str_replace("||", "", $pagerefs);
                    $wikipages['importfrombackup'][$i]['refs'] = wiki_treat_internal_ref($pagerefs);
                    $wikipages['importfrombackup'][$i]['lastmodified'] = $ewikipage['#']['LASTMODIFIED']['0']['#'];
                    $wikipages['importfrombackup'][$i]['oldentryid'] = $data["ENTRIES"]["0"]["#"]["ENTRY"]["0"]["#"]["ID"]["0"]["#"];
                    $wikipages['importfrombackup'][$i]['oldid'] = $data["ID"]["0"]["#"];
                    switch ($htmlmode) {
                        case '0':
                            $editor = 'ewiki';
                            break;
                        case '1':
                            $editor = 'ewiki';
                            break;
                        case '2':
                            $editor = 'htmleditor';
                            break;
                        default:
                            break;
                    }
                    $wikipages['importfrombackup'][$i]['editor'] = $editor;
                    $wikipages['importfrombackup'][$i]['groupid'] = $groupid;
                    $infouser = wiki_get_username($ewikipage['#']['AUTHOR']['0']['#']);
                    $wikipages['importfrombackup'][$i]['author'] = $infouser->username;
                    $wikipages['importfrombackup'][$i]['userid'] = $infouser->id;
                    $i++;
                }
            }
        }
    } else {
        error("Not exists wiki pages to import in the backup file.");
    }
    return $wikipages;
}