public/wordpress/wp-content/plugins/wp-courseware/includes/legacy/pages/page-quiz-modify.php
/**
 * Handle saving a feedback message to the database.
 *
 * @since 1.0.0
 *
 * @param integer $quizID The quiz for which the questions apply to.
 */
Handle saving a feedback message to the database.

@param integer $quizID The quiz for which the questions apply to.
Handle saving a feedback message to the database . @param integer $quizID The quiz for which the questions apply to .
function WPCW_showPage_customFeedback_processSave( $quizID ) {
	global $wpdb, $wpcwdb;
	$wpdb->show_errors();
	$msgToSave     = array();
	$msgToSave_New = array();
	foreach ( $_POST as $key => $value ) {
		if ( preg_match( '/^delete_wpcw_qcfm_sgl_wrapper_([0-9]+)$/', $key, $matches ) ) {
			$SQL = $wpdb->prepare( "
				DELETE FROM $wpcwdb->quiz_feedback
				WHERE qfeedback_id = %d
			", $matches[1] );
			$wpdb->query( $SQL );
		}
		if ( preg_match( '/^wpcw_qcfm_sgl_summary(_new_message)?_([0-9]+)$/', $key, $matches ) ) {
			$messageID = $matches[2];
			$newMessagePrefix = $matches[1];
			$fieldSuffix = $newMessagePrefix . '_' . $messageID;
			$messageFields = array(
				'qfeedback_quiz_id'     => $quizID,
				'qfeedback_summary'     => stripslashes( WPCW_arrays_getValue( $_POST, 'wpcw_qcfm_sgl_' . 'summary' . $fieldSuffix ) ),
				'qfeedback_message'     => stripslashes( WPCW_arrays_getValue( $_POST, 'wpcw_qcfm_sgl_' . 'message' . $fieldSuffix ) ),
				'qfeedback_tag_id'      => intval( WPCW_arrays_getValue( $_POST, 'wpcw_qcfm_sgl_' . 'tag' . $fieldSuffix ) ),
				'qfeedback_score_grade' => intval( WPCW_arrays_getValue( $_POST, 'wpcw_qcfm_sgl_' . 'score_grade' . $fieldSuffix ) ),
				'qfeedback_score_type'  => WPCW_arrays_getValue( $_POST, 'wpcw_qcfm_sgl_' . 'score_type' . $fieldSuffix ),
			);
			if ( 'below' != $messageFields['qfeedback_score_type'] && 'above' != $messageFields['qfeedback_score_type'] ) {
				$messageFields['qfeedback_score_type'] = 'below';
			}
			if ( $newMessagePrefix ) {
				$msgToSave_New[] = $messageFields;
			} else { 
				$messageFields['qfeedback_id'] = $messageID;
				$msgToSave[]                   = $messageFields;
			}
		}
	}
	if ( ! empty( $msgToSave_New ) ) {
		foreach ( $msgToSave_New as $messageDetails ) {
			$wpdb->query( arrayToSQLInsert( $wpcwdb->quiz_feedback, $messageDetails ) );
		}
	}
	if ( ! empty( $msgToSave ) ) {
		foreach ( $msgToSave as $messageDetails ) {
			$wpdb->query( arrayToSQLUpdate( $wpcwdb->quiz_feedback, $messageDetails, 'qfeedback_id' ) );
		}
	}
}
function WPCW_showPage_customFeedback_processSave ( $ quizID ) { global $ wpdb , $ wpcwdb ; $ wpdb -> show_errors ( ) ; $ msgToSave = array ( ) ; $ msgToSave_New = array ( ) ; foreach ( $ _POST as $ key => $ value ) { if ( preg_match ( '/^delete_wpcw_qcfm_sgl_wrapper_([0-9]+)$/' , $ key , $ matches ) ) { $ SQL = $ wpdb -> prepare ( " 
				DELETE FROM  $ wpcwdb -> quiz_feedback 
				WHERE qfeedback_id = %d
			 " , $ matches [ 1 ] ) ; $ wpdb -> query ( $ SQL ) ; } if ( preg_match ( '/^wpcw_qcfm_sgl_summary(_new_message)?_([0-9]+)$/' , $ key , $ matches ) ) { $ messageID = $ matches [ 2 ] ; $ newMessagePrefix = $ matches [ 1 ] ; $ fieldSuffix = $ newMessagePrefix . '_' . $ messageID ; $ messageFields = array ( 'qfeedback_quiz_id' => $ quizID , 'qfeedback_summary' => stripslashes ( WPCW_arrays_getValue ( $ _POST , 'wpcw_qcfm_sgl_' . 'summary' . $ fieldSuffix ) ) , 'qfeedback_message' => stripslashes ( WPCW_arrays_getValue ( $ _POST , 'wpcw_qcfm_sgl_' . 'message' . $ fieldSuffix ) ) , 'qfeedback_tag_id' => intval ( WPCW_arrays_getValue ( $ _POST , 'wpcw_qcfm_sgl_' . 'tag' . $ fieldSuffix ) ) , 'qfeedback_score_grade' => intval ( WPCW_arrays_getValue ( $ _POST , 'wpcw_qcfm_sgl_' . 'score_grade' . $ fieldSuffix ) ) , 'qfeedback_score_type' => WPCW_arrays_getValue ( $ _POST , 'wpcw_qcfm_sgl_' . 'score_type' . $ fieldSuffix ) , ) ; if ( 'below' != $ messageFields [ 'qfeedback_score_type' ] && 'above' != $ messageFields [ 'qfeedback_score_type' ] ) { $ messageFields [ 'qfeedback_score_type' ] = 'below' ; } if ( $ newMessagePrefix ) { $ msgToSave_New [ ] = $ messageFields ; } else { $ messageFields [ 'qfeedback_id' ] = $ messageID ; $ msgToSave [ ] = $ messageFields ; } } } if ( ! empty ( $ msgToSave_New ) ) { foreach ( $ msgToSave_New as $ messageDetails ) { $ wpdb -> query ( arrayToSQLInsert ( $ wpcwdb -> quiz_feedback , $ messageDetails ) ) ; } } if ( ! empty ( $ msgToSave ) ) { foreach ( $ msgToSave as $ messageDetails ) { $ wpdb -> query ( arrayToSQLUpdate ( $ wpcwdb -> quiz_feedback , $ messageDetails , 'qfeedback_id' ) ) ; } } }
Handle saving a feedback message to the database.
Handle saving a feedback message to the database .
// Check $_POST data for the // 1) - Check if we're deleting a custom feedback message // Delete the message from the message table // 2 - See if we have a custom feedback message to add or update // Checking for wpcw_qcfm_sgl_wrapper_1 or wpcw_qcfm_sgl_wrapper_new_message_1 // Got the ID of the message we're updating or adding. // Store the extra string if we're adding a new message. // Fetch each field we need that will be saved // Already have this, so not fetching from POST // Risk of slashes, hence removing them // Numbers // Fixed-width strings // Check we have a valid score type. // 3) - Not a new message - so add to list of new messages to add. // Existing message - so keep the message ID we have so we can update it. // 4) Add new messages // 5) Update existing messages