bookid; if( $bookid == 0){ print_error( get_string( 'bookquiz_not_select_book', 'game')); } if ($form = data_submitted()) { /// Filename if (empty($_FILES['newfile'])) { // file was just uploaded notify(get_string("uploadproblem") ); } if ((!is_uploaded_file($_FILES['newfile']['tmp_name']) or $_FILES['newfile']['size'] == 0)) { notify(get_string("uploadnofilefound") ); } else { // Valid file is found if ( readdata( $course->id, 'game', $dirtemp, $r_levels, $r_titles, $r_texts, $dirfordelete)) { // first try to reall all of the data in if( $overwrite){ game_bookquiz_deletebook( $course->id, $bookid); } $pageobjects = extract_data( $course->id, 'book', $bookid, $dirtemp, $subchapter, $r_levels, $r_titles, $r_texts); // parse all the html files into objects clean_temp( $dirfordelete); // all done with files so dump em $objects = game_bookquiz_create_objects( $pageobjects, $bookid); // function to preps the data to be sent to DB if( !game_bookquiz_save_objects($objects)) { // sends it to DB print_error('could not save'); } }else print_error('could not get data'); print_continue("{$CFG->wwwroot}/mod/game/view.php?id=$cm->id"); echo $OUTPUT->footer($course); exit; } } /// Print upload form print_heading_with_help( get_string( "bookquiz_import_odt", "game"), "importodt", "game"); echo $OUTPUT->box_start('center'); ?>
box_end(); echo $OUTPUT->footer($course); // START OF FUNCTIONS //the r_basedir variable contains the directory where the temp files are //At the end the directory must be deleted function readdata( $courseid, $modname, &$r_basedir, &$r_levels, &$r_titles, &$r_texts, &$dirfordelete) { // this function expects a odt file to be uploaded. Then it parses // the content.xml to determine. // Then copies the image global $CFG; // create a random upload directory in temp $newdir = $CFG->dataroot."/temp/$modname"; if (!file_exists( $newdir)) mkdir( $newdir); $i = 1; srand((double)microtime()*1000000); while(true) { $r_basedir = "$modname/$i-".rand(0,10000); $newdir = $CFG->dataroot.'/temp/'.$r_basedir; if (!file_exists( $newdir)) { mkdir( $newdir); $newdir .= '/'; break; } $i++; } $dirfordelete = $r_basedir; $r_basedir .= '/'; $zipfile = $_FILES["newfile"]["name"]; $tempzipfile = $_FILES["newfile"]["tmp_name"]; // create our directory $path_parts = pathinfo($zipfile); $dirname = substr($zipfile, 0, strpos($zipfile, '.'.$path_parts['extension'])); // take off the extension if (!file_exists($newdir.$dirname)){ mkdir($newdir.$dirname); } // move our uploaded file to temp/game move_uploaded_file( $tempzipfile, $newdir.$zipfile); //if the file ends with .lnk then use .odt instead if( substr( $zipfile, -4) == ".lnk") $zipfile = substr( $zipfile, 0, -4).".odt"; // unzip it! unzip_file ( $newdir.$zipfile, $newdir.$dirname, false); $r_basedir .= $dirname; // update the base $newdir .= $dirname; // this is the file where we get the names of the files for the slides (in the correct order too) $content = $newdir.'/content.xml'; $data = file_get_contents( $content); $content = $newdir.'/styles.xml'; if (file_exists( $content)){ $datastyle = file_get_contents( $content); }else { $datastyle = ''; } oo_game_convert_ver2( $data, $datastyle, $r_levels, $r_titles, $r_texts); return true; } //////////////////////// function oo_game_convert_ver2( $data, $datastyle, &$r_levels, &$r_titles, &$r_texts) { $r_levels = array(); $r_titles = array(); $r_texts = array(); // we have tables, encode it here so all'.$content.'
'; $chapter->content = addslashes( $content); $chapters[] = $chapter; } return $chapters; } /** Save the chapter objects to the database */ function game_bookquiz_save_objects($chapters) { global $DB; // nothing fancy, just save them all in order foreach ($chapters as $chapter) { if (!$newid=$DB->insert_record('book_chapters', $chapter)) { print_error('Could not insert to table book_chapters'); } } return true; } //splits the data to function game_bookquiz_splitsections($data, &$positions, &$inputs, &$titles, &$titleframes, &$texts) { preg_match_all('#'.game_bookquiz_convert_text( $text, $styles).'
'; $data = str_replace( $originals[ $i], $new, $data); } } // repairs text:span text:style-name preg_match_all( '#', $table);
$table = str_replace($val, '
|