public/wordpress/wp-content/plugins/wp-courseware/includes/legacy/classes/export.php
/**
		 * 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.
		 */
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.
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 ) {
			if ( isset( $_POST["update"] ) && $_POST["update"] == 'wpcw_export' ) {
				if ( ! is_user_logged_in() ) {
					wp_die( __( 'You do not have sufficient permissions to access this page.', 'wp-courseware' ) );
				}
				$current_user = wp_get_current_user();
				if ( ! user_can( $current_user, 'view_wpcw_courses' ) ) {
					wp_die( __( 'You do not have sufficient permissions to export course data.', 'wp-courseware' ) );
				}
				$courseID      = WPCW_arrays_getValue( $_POST, 'export_course_id' );
				$courseDetails = WPCW_courses_getCourseDetails( $courseID );
				 permissions to export details.
				if ( $courseDetails && ! user_can( $current_user, 'manage_wpcw_settings' ) && $current_user->ID != $courseDetails->course_author ) {
					wp_die( __( 'You do not have sufficient permissions to export data from this course.', 'wp-courseware' ) );
				}
				 course details.
				if ( $courseDetails ) {
					$moduleList   = false;
					$questionList = false;
					$whatToExport = WPCW_arrays_getValue( $_POST, 'what_to_export' );
					switch ( $whatToExport ) {
						case 'just_course':
							break;
						case 'course_modules':
							$moduleList = WPCW_courses_getModuleDetailsList( $courseDetails->course_id );
							break;
						case 'course_modules_and_units':
							$moduleList = WPCW_courses_getModuleDetailsList( $courseDetails->course_id );
							if ( $moduleList ) {
								foreach ( $moduleList as $module ) {
									$module->units = WPCW_units_getListOfUnits( $module->module_id );
								}
							}
							break;
						default:
							$questionList = WPCW_questions_getAllQuestionsforCourse( $courseDetails->course_id );
							$moduleList = WPCW_courses_getModuleDetailsList( $courseDetails->course_id );
							if ( $moduleList ) {
								foreach ( $moduleList as $module ) {
									$module->units = WPCW_units_getListOfUnits( $module->module_id );
									WPCW_Export::WPCW_quizzes_fetchQuizzesForUnits( $module->units );
								}
							}
							break;
					}
					$triggerFileDownload = true;
					if ( $triggerFileDownload ) {
						$course_title = sprintf( '%s', 'wp-courseware', $courseDetails->course_title );
						$exportFile   = "wp-courseware-export-" . sanitize_title( $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 {
						header( 'Content-Type: text/plain' );
					}
					$export = new WPCW_Export();
					echo $export->exportCourseDetails( $courseDetails, $moduleList, $questionList );
					die();
				}
			}
		}
public static function tryExportCourse ( $ triggerFileDownload = true ) { if ( isset ( $ _POST [ " update " ] ) && $ _POST [ " update " ] == 'wpcw_export' ) { if ( ! is_user_logged_in ( ) ) { wp_die ( __ ( 'You do not have sufficient permissions to access this page.' , 'wp-courseware' ) ) ; } $ current_user = wp_get_current_user ( ) ; if ( ! user_can ( $ current_user , 'view_wpcw_courses' ) ) { wp_die ( __ ( 'You do not have sufficient permissions to export course data.' , 'wp-courseware' ) ) ; } $ courseID = WPCW_arrays_getValue ( $ _POST , 'export_course_id' ) ; $ courseDetails = WPCW_courses_getCourseDetails ( $ courseID ) ; if ( $ courseDetails && ! user_can ( $ current_user , 'manage_wpcw_settings' ) && $ current_user -> ID != $ courseDetails -> course_author ) { wp_die ( __ ( 'You do not have sufficient permissions to export data from this course.' , 'wp-courseware' ) ) ; } if ( $ courseDetails ) { $ moduleList = false ; $ questionList = false ; $ whatToExport = WPCW_arrays_getValue ( $ _POST , 'what_to_export' ) ; switch ( $ whatToExport ) { case 'just_course' : break ; case 'course_modules' : $ moduleList = WPCW_courses_getModuleDetailsList ( $ courseDetails -> course_id ) ; break ; case 'course_modules_and_units' : $ moduleList = WPCW_courses_getModuleDetailsList ( $ courseDetails -> course_id ) ; if ( $ moduleList ) { foreach ( $ moduleList as $ module ) { $ module -> units = WPCW_units_getListOfUnits ( $ module -> module_id ) ; } } break ; default : $ questionList = WPCW_questions_getAllQuestionsforCourse ( $ courseDetails -> course_id ) ; $ moduleList = WPCW_courses_getModuleDetailsList ( $ courseDetails -> course_id ) ; if ( $ moduleList ) { foreach ( $ moduleList as $ module ) { $ module -> units = WPCW_units_getListOfUnits ( $ module -> module_id ) ; WPCW_Export :: WPCW_quizzes_fetchQuizzesForUnits ( $ module -> units ) ; } } break ; } $ triggerFileDownload = true ; if ( $ triggerFileDownload ) { $ course_title = sprintf ( '%s' , 'wp-courseware' , $ courseDetails -> course_title ) ; $ exportFile = " wp-courseware-export- " . sanitize_title ( $ 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 { header ( 'Content-Type: text/plain' ) ; } $ export = new WPCW_Export ( ) ; echo $ export -> exportCourseDetails ( $ courseDetails , $ moduleList , $ questionList ) ; die ( ) ; } } }
See if there's a course to export based on $_POST variables.
See if there ' s a course to export based on $_POST variables .
// See if course is being exported // Check logged in. // Current User // Check // Now check course is valid. If not, then don't do anything, and let // normal form handle the errors. // Check permissions to export details. // Check course details. // Work out what details to fetch and then export // Course Settings: Yes // Module Settings: No // 			 Units: No // 	 	   Quizzes: No // Course Settings: Yes // Module Settings: Yes // 			 Units: No // 	 	   Quizzes: No // Course Settings: Yes // Module Settings: Yes // 			 Units: Yes // 	 	   Quizzes: No // Grab units for each module, in the right order, and associate with each module object. // This might return false, but that's OK. We'll check for it later. // Basically the whole course // Course Settings: Yes // Module Settings: Yes // 			 Units: Yes // 	 	   Quizzes: Yes // Grab units for each module, in the right order, and associate with each module object. // This might return false, but that's OK. We'll check for it later. // See if we have any units, and then check each for the associated quiz data. // Update the unit objects with details of the quizzes // TODO ZZZ - DEBUG Tool - To enable debugging, comment this in so that the download is not triggered. // If true, trigger a file download of the XML file. // When debugging, comment out the line above, and use the following line so that you can see // any error messages. // If get here, then normal WPCW processing takes place.