get_record('course', array( 'id' => $cm->course))) { print_error('Course is misconfigured'); } // allows for adaption for multiple modules if(! $modname = $DB->get_field('modules', 'name', array( 'id' => $cm->module))) { print_error('Could not find module name'); } if (! $mod = $DB->get_record($modname, array( "id" => $cm->instance))) { print_error('Course module is incorrect'); } require_login($course->id, false); $context = get_context_instance(CONTEXT_MODULE, $cm->id); require_capability('mod/lesson:edit', $context); $strimportppt = get_string("importppt", "lesson"); $strlessons = get_string("modulenameplural", "lesson"); echo $OUTPUT->heading("$strimportppt", " $strimportppt", "id\">$strlessons -> wwwroot}/mod/$modname/view.php?id=$cm->id\">".format_string($mod->name,true)."-> $strimportppt"); 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 ($rawpages = readdata($_FILES, $course->id, $modname)) { // first try to reall all of the data in $pageobjects = extract_data($rawpages, $course->id, $mod->name, $modname); // parse all the html files into objects clean_temp(); // all done with files so dump em $mod_create_objects = $modname.'_create_objects'; $mod_save_objects = $modname.'_save_objects'; $objects = $mod_create_objects($pageobjects, $mod->id); // function to preps the data to be sent to DB if(! $mod_save_objects($objects, $mod->id, $pageid)) { // sends it to DB print_error( 'could not save'); } } else { print_error('could not get data'); } echo "
tags around each element and strip out \n which I have found to be uneccessary foreach ($pageobject->contents as $content) { $content = str_replace("\n", '', $content); $content = str_replace("\r", '', $content); $content = str_replace(' ', '', $content); // puts in returns? $content = '
'.$content.'
'; $page->contents .= addslashes($content); } return $page; } /** Save the chapter objects to the database */ function book_save_objects($chapters, $bookid, $pageid='0') { global $DB; // nothing fancy, just save them all in order foreach ($chapters as $chapter) { if (!$chapter->id = $DB->insert_record('book_chapters', $chapter)) { print_error('Could not update your book'); } } return true; }