public/wordpress/wp-content/plugins/wp-courseware/includes/legacy/admin/functions.php
/**
 * Code that checks if we're resetting the user progress.
 *
 * @since 1.0.0
 */
Code that checks if we're resetting the user progress.
Code that checks if we ' re resetting the user progress .
function WPCW_users_processUserResetAbility() {
	$resetTypeCommand = WPCW_arrays_getValue( $_GET, 'wpcw_user_progress_reset_point_bulk' );
	if ( ! $resetTypeCommand ) {
		$resetTypeCommand = WPCW_arrays_getValue( $_GET, 'wpcw_user_progress_reset_point_single' );
	}
	if ( $resetTypeCommand ) {
		if ( ! preg_match( '/^(course|module|unit)_([0-9]+)$/', $resetTypeCommand, $matches ) ) {
			wp_redirect( add_query_arg( array( 'page' => 'wpcw-students', 'wpcw_reset' => false ), admin_url( 'admin.php' ) ) );
			die();
		}
		$userList        = array();
		$classroom_reset = false;
		if ( isset( $_GET['users'] ) ) {
			$userList = array_map( 'intval', (array) $_GET['users'] );
		} elseif ( isset( $_GET['student_id'] ) && isset( $_GET['bulk_course_id'] ) && isset( $_GET['wpcw_user_bulk_progress_reset'] ) ) {
			$userList = array_map( 'intval', (array) $_GET['student_id'] );
		} elseif ( isset( $_GET['bulk_course_id'] ) && isset( $_GET['wpcw_classroom_bulk_progress_reset'] ) ) {
			$classroom_reset = true;
		} else if ( isset( $_GET['wpcw_users_single'] ) && isset( $_GET['wpcw_user_progress_reset_point_single'] ) && $_GET['wpcw_user_progress_reset_point_single'] ) {
			$userList[] = intval( $_GET['wpcw_users_single'] );
		}
		if ( empty( $userList ) && ! $classroom_reset ) {
			if ( isset( $_GET['course_id'] ) || isset( $_GET['bulk_course_id'] ) ) {
				$course_id = isset( $_GET['course_id'] ) ? $_GET['course_id'] : $_GET['bulk_course_id'];
				wp_redirect( add_query_arg( array( 'page' => 'wpcw-course-classroom', 'course_id' => absint( $course_id ), 'wpcw_reset' => false ), admin_url( 'admin.php' ) ) );
			} elseif ( isset( $_GET['wpcw_student_reset_page'] ) && isset( $_GET['wpcw_student'] ) ) {
				wp_redirect( add_query_arg( array(
					'page'       => esc_attr( $_GET['wpcw_student_reset_page'] ),
					'id'         => absint( $_GET['wpcw_student'] ),
					'wpcw_reset' => false,
				), admin_url( 'admin.php' ) ) );
			} else {
				wp_redirect( add_query_arg( array( 'page' => 'wpcw-students', 'wpcw_reset' => false ), admin_url( 'admin.php' ) ) );
			}
			die();
		}
		$unitList  = false;
		$courseMap = new WPCW_CourseMap();
		switch ( $matches[1] ) {
			case 'unit':
				$courseMap->loadDetails_byUnitID( $matches[2] );
				$unitList = $courseMap->getUnitIDList_afterUnit( $matches[2] );
				break;
			case 'module':
				$courseMap->loadDetails_byModuleID( $matches[2] );
				$unitList = $courseMap->getUnitIDList_afterModule( $matches[2] );
				break;
			case 'course':
				$courseMap->loadDetails_byCourseID( $matches[2] );
				$unitList = $courseMap->getUnitIDList_forCourse();
				break;
			default:
				wp_redirect( add_query_arg( array( 'page' => 'wpcw-students', 'wpcw_reset' => false ), admin_url( 'admin.php' ) ) );
				die();
				break;
		}
		if ( empty( $userList ) && $classroom_reset ) {
			if ( isset( $_GET['course_id'] ) || isset( $_GET['bulk_course_id'] ) ) {
				$course_id = isset( $_GET['course_id'] ) ? $_GET['course_id'] : $_GET['bulk_course_id'];
				$userList  = wpcw()->students->get_students( array( 'course_id' => absint( $course_id ), 'number' => - 1, 'fields' => 'ids' ) );
			}
		}
		WPCW_users_resetProgress( $userList, $unitList, $courseMap->getCourseDetails(), $courseMap->getUnitCount() );
		if ( $classroom_reset ) {
			wp_redirect( add_query_arg( array( 'page' => 'wpcw-course-classroom', 'course_id' => absint( $course_id ), 'wpcw_reset_classroom' => true ), admin_url( 'admin.php' ) ) );
			exit;
		}
		if ( isset( $_GET['course_id'] ) || isset( $_GET['bulk_course_id'] ) ) {
			$course_id = isset( $_GET['course_id'] ) ? $_GET['course_id'] : $_GET['bulk_course_id'];
			wp_redirect( add_query_arg( array( 'page' => 'wpcw-course-classroom', 'course_id' => absint( $course_id ), 'wpcw_reset' => 'true' ), admin_url( 'admin.php' ) ) );
		} elseif ( isset( $_GET['wpcw_student_reset_page'] ) && isset( $_GET['wpcw_student'] ) ) {
			wp_redirect( add_query_arg( array(
				'page'       => esc_attr( $_GET['wpcw_student_reset_page'] ),
				'id'         => absint( $_GET['wpcw_student'] ),
				'wpcw_reset' => true,
			), admin_url( 'admin.php' ) ) );
		} else {
			wp_redirect( add_query_arg( array( 'page' => 'wpcw-students', 'wpcw_reset' => 'true' ), admin_url( 'admin.php' ) ) );
		}
		die();
	}
}
function WPCW_users_processUserResetAbility ( ) { $ resetTypeCommand = WPCW_arrays_getValue ( $ _GET , 'wpcw_user_progress_reset_point_bulk' ) ; if ( ! $ resetTypeCommand ) { $ resetTypeCommand = WPCW_arrays_getValue ( $ _GET , 'wpcw_user_progress_reset_point_single' ) ; } if ( $ resetTypeCommand ) { if ( ! preg_match ( '/^(course|module|unit)_([0-9]+)$/' , $ resetTypeCommand , $ matches ) ) { wp_redirect ( add_query_arg ( array ( 'page' => 'wpcw-students' , 'wpcw_reset' => false ) , admin_url ( 'admin.php' ) ) ) ; die ( ) ; } $ userList = array ( ) ; $ classroom_reset = false ; if ( isset ( $ _GET [ 'users' ] ) ) { $ userList = array_map ( 'intval' , ( array ) $ _GET [ 'users' ] ) ; } elseif ( isset ( $ _GET [ 'student_id' ] ) && isset ( $ _GET [ 'bulk_course_id' ] ) && isset ( $ _GET [ 'wpcw_user_bulk_progress_reset' ] ) ) { $ userList = array_map ( 'intval' , ( array ) $ _GET [ 'student_id' ] ) ; } elseif ( isset ( $ _GET [ 'bulk_course_id' ] ) && isset ( $ _GET [ 'wpcw_classroom_bulk_progress_reset' ] ) ) { $ classroom_reset = true ; } else if ( isset ( $ _GET [ 'wpcw_users_single' ] ) && isset ( $ _GET [ 'wpcw_user_progress_reset_point_single' ] ) && $ _GET [ 'wpcw_user_progress_reset_point_single' ] ) { $ userList [ ] = intval ( $ _GET [ 'wpcw_users_single' ] ) ; } if ( empty ( $ userList ) && ! $ classroom_reset ) { if ( isset ( $ _GET [ 'course_id' ] ) || isset ( $ _GET [ 'bulk_course_id' ] ) ) { $ course_id = isset ( $ _GET [ 'course_id' ] ) ? $ _GET [ 'course_id' ] : $ _GET [ 'bulk_course_id' ] ; wp_redirect ( add_query_arg ( array ( 'page' => 'wpcw-course-classroom' , 'course_id' => absint ( $ course_id ) , 'wpcw_reset' => false ) , admin_url ( 'admin.php' ) ) ) ; } elseif ( isset ( $ _GET [ 'wpcw_student_reset_page' ] ) && isset ( $ _GET [ 'wpcw_student' ] ) ) { wp_redirect ( add_query_arg ( array ( 'page' => esc_attr ( $ _GET [ 'wpcw_student_reset_page' ] ) , 'id' => absint ( $ _GET [ 'wpcw_student' ] ) , 'wpcw_reset' => false , ) , admin_url ( 'admin.php' ) ) ) ; } else { wp_redirect ( add_query_arg ( array ( 'page' => 'wpcw-students' , 'wpcw_reset' => false ) , admin_url ( 'admin.php' ) ) ) ; } die ( ) ; } $ unitList = false ; $ courseMap = new WPCW_CourseMap ( ) ; switch ( $ matches [ 1 ] ) { case 'unit' : $ courseMap -> loadDetails_byUnitID ( $ matches [ 2 ] ) ; $ unitList = $ courseMap -> getUnitIDList_afterUnit ( $ matches [ 2 ] ) ; break ; case 'module' : $ courseMap -> loadDetails_byModuleID ( $ matches [ 2 ] ) ; $ unitList = $ courseMap -> getUnitIDList_afterModule ( $ matches [ 2 ] ) ; break ; case 'course' : $ courseMap -> loadDetails_byCourseID ( $ matches [ 2 ] ) ; $ unitList = $ courseMap -> getUnitIDList_forCourse ( ) ; break ; default : wp_redirect ( add_query_arg ( array ( 'page' => 'wpcw-students' , 'wpcw_reset' => false ) , admin_url ( 'admin.php' ) ) ) ; die ( ) ; break ; } if ( empty ( $ userList ) && $ classroom_reset ) { if ( isset ( $ _GET [ 'course_id' ] ) || isset ( $ _GET [ 'bulk_course_id' ] ) ) { $ course_id = isset ( $ _GET [ 'course_id' ] ) ? $ _GET [ 'course_id' ] : $ _GET [ 'bulk_course_id' ] ; $ userList = wpcw ( ) -> students -> get_students ( array ( 'course_id' => absint ( $ course_id ) , 'number' => - 1 , 'fields' => 'ids' ) ) ; } } WPCW_users_resetProgress ( $ userList , $ unitList , $ courseMap -> getCourseDetails ( ) , $ courseMap -> getUnitCount ( ) ) ; if ( $ classroom_reset ) { wp_redirect ( add_query_arg ( array ( 'page' => 'wpcw-course-classroom' , 'course_id' => absint ( $ course_id ) , 'wpcw_reset_classroom' => true ) , admin_url ( 'admin.php' ) ) ) ; exit ; } if ( isset ( $ _GET [ 'course_id' ] ) || isset ( $ _GET [ 'bulk_course_id' ] ) ) { $ course_id = isset ( $ _GET [ 'course_id' ] ) ? $ _GET [ 'course_id' ] : $ _GET [ 'bulk_course_id' ] ; wp_redirect ( add_query_arg ( array ( 'page' => 'wpcw-course-classroom' , 'course_id' => absint ( $ course_id ) , 'wpcw_reset' => 'true' ) , admin_url ( 'admin.php' ) ) ) ; } elseif ( isset ( $ _GET [ 'wpcw_student_reset_page' ] ) && isset ( $ _GET [ 'wpcw_student' ] ) ) { wp_redirect ( add_query_arg ( array ( 'page' => esc_attr ( $ _GET [ 'wpcw_student_reset_page' ] ) , 'id' => absint ( $ _GET [ 'wpcw_student' ] ) , 'wpcw_reset' => true , ) , admin_url ( 'admin.php' ) ) ) ; } else { wp_redirect ( add_query_arg ( array ( 'page' => 'wpcw-students' , 'wpcw_reset' => 'true' ) , admin_url ( 'admin.php' ) ) ) ; } die ( ) ; } }
Code that checks if we're resetting the user progress.
Code that checks if we ' re resetting the user progress .
// Check bulk by default, otherwise check the single user change. // Detect the reset command. // Check for a specific module/unit/course to reset. If none found, then refresh. // No parameter found, reset. // Check array of users first (as not triggered for a single update) // Check if we've chosen any users to reset. If not, reset. // Add a single user ID. // No users at all. // See what we tried to reset to. // No parameter found, reset. // Classroom Reset. // Now do the reset of the progress. // Classroom Reset. // Redirect to remove the GET flags from the URL.