/** * See if there's a course to export based on $_POST variables. If so, trigger the export and XML download. * @param Boolean $triggerFileDownload If true, trigger a file download rather than just XML output as a page. */ public static function tryExportCourse($triggerFileDownload = true) { // See if course is being exported if (isset($_POST["update"]) && $_POST["update"] == 'wpcw_export' && current_user_can('manage_options')) { // Now check course is valid. If not, then don't do anything, and let // normal form handle the errors. $courseID = WPCW_arrays_getValue($_POST, 'export_course_id'); $courseDetails = WPCW_courses_getCourseDetails($courseID); if ($courseDetails) { $moduleList = false; // Work out what details to fetch and then export $whatToExport = WPCW_arrays_getValue($_POST, 'what_to_export'); switch ($whatToExport) { // Just the course title, description and settings (no units or modules) case 'just_course': break; // Just the course settings and module settings (no units) // Just the course settings and module settings (no units) case 'course_modules': $moduleList = WPCW_courses_getModuleDetailsList($courseDetails->course_id); break; // Basically case 'whole_course' - The whole course, modules and units // Basically case 'whole_course' - The whole course, modules and units default: $moduleList = WPCW_courses_getModuleDetailsList($courseDetails->course_id); if ($moduleList) { // Grab units for each module, in the right order, and associate with each module object. foreach ($moduleList as $module) { // This might return false, but that's OK. We'll check for it later. $module->units = WPCW_units_getListOfUnits($module->module_id); } } break; } // If true, trigger a file download of the XML file. if ($triggerFileDownload) { $exportFile = "wp-courseware-export-" . date("Y-m-d") . ".xml"; header('Content-Description: File Transfer'); header("Content-Disposition: attachment; filename={$exportFile}"); } header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true); // When debugging, comment out the line above, and use the following line so that you can see // any error messages. // header('Content-Type: text/plain'); $export = new WPCW_Export(); echo $export->exportCourseDetails($courseDetails, $moduleList); die; } } // If get here, then normal WPCW processing takes place. }
/** * See if there's a course to export based on $_POST variables. If so, trigger the export and XML download. * @param Boolean $triggerFileDownload If true, trigger a file download rather than just XML output as a page. */ public static function tryExportCourse($triggerFileDownload = true) { // See if course is being exported if (isset($_POST["update"]) && $_POST["update"] == 'wpcw_export' && current_user_can('manage_options')) { // Now check course is valid. If not, then don't do anything, and let // normal form handle the errors. $courseID = WPCW_arrays_getValue($_POST, 'export_course_id'); $courseDetails = WPCW_courses_getCourseDetails($courseID); if ($courseDetails) { $moduleList = false; $questionList = false; // Work out what details to fetch and then export $whatToExport = WPCW_arrays_getValue($_POST, 'what_to_export'); switch ($whatToExport) { // Course Settings: Yes // Module Settings: No // Units: No // Quizzes: No case 'just_course': break; // Course Settings: Yes // Module Settings: Yes // Units: No // Quizzes: No // Course Settings: Yes // Module Settings: Yes // Units: No // Quizzes: No case 'course_modules': $moduleList = WPCW_courses_getModuleDetailsList($courseDetails->course_id); break; // Course Settings: Yes // Module Settings: Yes // Units: Yes // Quizzes: No // Course Settings: Yes // Module Settings: Yes // Units: Yes // Quizzes: No case 'course_modules_and_units': $moduleList = WPCW_courses_getModuleDetailsList($courseDetails->course_id); if ($moduleList) { // Grab units for each module, in the right order, and associate with each module object. foreach ($moduleList as $module) { // This might return false, but that's OK. We'll check for it later. $module->units = WPCW_units_getListOfUnits($module->module_id); } } break; // Basically the whole course // Course Settings: Yes // Module Settings: Yes // Units: Yes // Quizzes: Yes // Basically the whole course // Course Settings: Yes // Module Settings: Yes // Units: Yes // Quizzes: Yes default: $questionList = WPCW_questions_getAllQuestionsforCourse($courseDetails->course_id); $moduleList = WPCW_courses_getModuleDetailsList($courseDetails->course_id); if ($moduleList) { // Grab units for each module, in the right order, and associate with each module object. foreach ($moduleList as $module) { // This might return false, but that's OK. We'll check for it later. $module->units = WPCW_units_getListOfUnits($module->module_id); // See if we have any units, and then check each for the associated quiz data. // Update the unit objects with details of the quizzes WPCW_Export::WPCW_quizzes_fetchQuizzesForUnits($module->units); } } break; } // TODO ZZZ - DEBUG Tool - To enable debugging, comment this in so that the download is not triggered. $triggerFileDownload = true; // If true, trigger a file download of the XML file. if ($triggerFileDownload) { $exportFile = "wp-courseware-export-" . sanitize_title($courseDetails->course_title) . '-' . date("Y-m-d") . ".xml"; header('Content-Description: File Transfer'); header("Content-Disposition: attachment; filename={$exportFile}"); header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true); } else { // When debugging, comment out the line above, and use the following line so that you can see // any error messages. header('Content-Type: text/plain'); } $export = new WPCW_Export(); echo $export->exportCourseDetails($courseDetails, $moduleList, $questionList); die; } } // If get here, then normal WPCW processing takes place. }