public/wordpress/wp-content/plugins/wp-courseware/includes/legacy/functions.php
/**
 * Function to upgrade the database tables.
 *
 * @since 1.0.0
 *
 * @param integer $installedVersion The version that exists prior to the upgrade.
 * @param boolean $forceUpgrade If true, we force an upgrade.
 * @param boolean $showErrors If true, show any debug errors.
 */
Function to upgrade the database tables.

@param integer $installedVersion The version that exists prior to the upgrade.
@param boolean $forceUpgrade If true, we force an upgrade.
@param boolean $showErrors If true, show any debug errors.
Function to upgrade the database tables . @param integer $installedVersion The version that exists prior to the upgrade . @param boolean $forceUpgrade If true we force an upgrade . @param boolean $showErrors If true show any debug errors .
function WPCW_database_upgradeTables( $installedVersion, $forceUpgrade, $showErrors = false ) {
	global $wpdb, $wpcwdb;
	if ( $showErrors ) {
		$wpdb->show_errors();
	}
	$upgradeNow = true;
	$SQL = "CREATE TABLE $wpcwdb->courses (
			  course_id int(11) unsigned NOT NULL AUTO_INCREMENT,
			  course_title varchar(150) NOT NULL,
			  course_desc text NULL,
			  course_author bigint(20) unsigned NOT NULL default '0',
			  course_opt_completion_wall varchar(20) NOT NULL,
			  course_opt_use_certificate varchar(20) NOT NULL DEFAULT 'no_certs',
			  course_opt_user_access varchar(20) NOT NULL,
			  course_unit_count int(11) unsigned NULL DEFAULT '0',
			  course_from_name varchar(150) NOT NULL,
			  course_from_email varchar(150) NOT NULL,
			  course_to_email varchar(150) NOT NULL,
			  course_opt_prerequisites longtext NOT NULL,
			  course_message_unit_complete text NULL,
			  course_message_course_complete text NULL,
			  course_message_unit_not_logged_in text NULL,
			  course_message_unit_pending text NULL,
			  course_message_unit_no_access text NULL,
			  course_message_prerequisite_not_met text NULL,
			  course_message_unit_not_yet text NULL,
			  course_message_unit_not_yet_dripfeed text NULL,
			  course_message_quiz_open_grading_blocking text NULL,
			  course_message_quiz_open_grading_non_blocking text NULL,
			  email_complete_module_option_admin varchar(20) NOT NULL,
			  email_complete_module_option varchar(20) NOT NULL,
			  email_complete_module_subject varchar(300) NOT NULL,
			  email_complete_module_body text NULL,
			  email_complete_course_option_admin varchar(20) NOT NULL,
			  email_complete_course_option varchar(20) NOT NULL,
			  email_complete_course_subject varchar(300) NOT NULL,
			  email_complete_course_body text NULL,
			  email_quiz_grade_option varchar(20) NOT NULL,
			  email_quiz_grade_subject varchar(300) NOT NULL,
			  email_quiz_grade_body text NULL,
			  email_complete_course_grade_summary_subject varchar(300) NOT NULL,
			  email_complete_course_grade_summary_body text NULL,
			  email_unit_unlocked_subject varchar(300) NOT NULL,
			  email_unit_unlocked_body text NULL,
			  cert_signature_type varchar(20) NOT NULL DEFAULT 'text',
			  cert_sig_text varchar(300) NOT NULL,
			  cert_sig_image_url varchar(300) NOT NULL DEFAULT  '',
			  cert_logo_enabled varchar(20) NOT NULL DEFAULT 'no_cert_logo',
			  cert_logo_url varchar(300) NOT NULL DEFAULT '',
			  cert_background_type varchar(20) NOT NULL DEFAULT 'use_default',
			  cert_background_custom_url varchar(300) NOT NULL DEFAULT  '',
			  PRIMARY KEY  (course_id)
			) ENGINE=InnoDB  DEFAULT CHARSET=utf8";
	WPCW_database_installTable( $wpcwdb->courses, $SQL, $upgradeNow );
	$SQL = "CREATE TABLE $wpcwdb->modules (
			  module_id int(11) unsigned NOT NULL AUTO_INCREMENT,
			  parent_course_id int(11) unsigned NOT NULL DEFAULT '0',
			  module_author bigint(20) unsigned NOT NULL default '0',
			  module_title varchar(150) NOT NULL,
			  module_desc text NULL,
			  module_order int(11) unsigned NOT NULL DEFAULT '10000',
			  module_number int(11) unsigned NOT NULL DEFAULT '0',
			  PRIMARY KEY  (module_id)
			) ENGINE=InnoDB  DEFAULT CHARSET=utf8;";
	WPCW_database_installTable( $wpcwdb->modules, $SQL, $upgradeNow );
	$SQL = "CREATE TABLE $wpcwdb->units_meta (
			  unit_id int(11) unsigned NOT NULL,
			  parent_module_id int(11) unsigned NOT NULL DEFAULT '0',
			  parent_course_id int(11) unsigned NOT NULL DEFAULT '0',
			  unit_author bigint(20) unsigned NOT NULL default '0',
			  unit_order int(11) unsigned NOT NULL DEFAULT '0',
			  unit_number int(11) unsigned NOT NULL DEFAULT '0',
			  unit_drip_type varchar(50) NOT NULL DEFAULT '',
			  unit_drip_date datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
			  unit_drip_interval int(11) NOT NULL DEFAULT '432000',
			  unit_drip_interval_type varchar(15) NOT NULL DEFAULT 'interval_days',
			  PRIMARY KEY  (unit_id)
			) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
	WPCW_database_installTable( $wpcwdb->units_meta, $SQL, $upgradeNow );
	$SQL = "CREATE TABLE $wpcwdb->user_courses (
			  user_id int(11) unsigned NOT NULL,
			  course_id int(11) unsigned NOT NULL,
			  course_progress int(11) NOT NULL DEFAULT '0',
			  course_final_grade_sent VARCHAR(30) NOT NULL DEFAULT '',
			  course_enrolment_date datetime DEFAULT '0000-00-00 00:00:00',
			  UNIQUE KEY user_id (user_id,course_id)
			) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
	WPCW_database_installTable( $wpcwdb->user_courses, $SQL, $upgradeNow );
	$SQL = "CREATE TABLE $wpcwdb->user_progress (
			  user_id int(11) unsigned NOT NULL,
			  unit_id int(11) unsigned NOT NULL,
			  unit_completed_date datetime DEFAULT NULL,
			  unit_completed_status varchar(20) NOT NULL,
			  PRIMARY KEY  (user_id,unit_id)
			) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
	WPCW_database_installTable( $wpcwdb->user_progress, $SQL, $upgradeNow );
	$SQL = "CREATE TABLE $wpcwdb->quiz (
			  quiz_id int(11) unsigned NOT NULL AUTO_INCREMENT,
			  quiz_title varchar(150) NOT NULL,
			  quiz_desc text NULL,
			  quiz_author bigint(20) unsigned NOT NULL default '0',
			  parent_unit_id int(11) unsigned NOT NULL DEFAULT '0',
			  parent_course_id int(11) NOT NULL DEFAULT '0',
			  quiz_type varchar(15) NOT NULL,
			  quiz_pass_mark int(11) NOT NULL DEFAULT '0',
			  quiz_show_answers varchar(15) NOT NULL DEFAULT 'no_answers',
			  quiz_show_survey_responses varchar(15) NOT NULL DEFAULT 'no_responses',
			  quiz_attempts_allowed int(11) NOT NULL DEFAULT '-1',
			  show_answers_settings VARCHAR(500) NOT NULL DEFAULT '',
			  quiz_paginate_questions VARCHAR(15) NOT NULL DEFAULT 'no_paging',
			  quiz_paginate_questions_settings VARCHAR(500) NOT NULL DEFAULT '',
			  quiz_timer_mode varchar(25) NOT NULL DEFAULT 'no_timer',
			  quiz_timer_mode_limit int(11) unsigned NOT NULL DEFAULT '15',
			  quiz_results_downloadable varchar(10) NOT NULL DEFAULT 'on',
			  quiz_results_by_tag varchar(10) NOT NULL DEFAULT 'on',
			  quiz_results_by_timer varchar(10) NOT NULL DEFAULT 'on',
			  quiz_recommended_score varchar(20) NOT NULL DEFAULT 'no_recommended',
			  show_recommended_percentage int(10) unsigned NOT NULL DEFAULT 50,
			  PRIMARY KEY  (quiz_id)
			) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
	WPCW_database_installTable( $wpcwdb->quiz, $SQL, $upgradeNow );
	$SQL = "CREATE TABLE $wpcwdb->quiz_qs (
			  question_id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
			  question_author bigint(20) unsigned NOT NULL default '0',
			  question_type VARCHAR(20) NOT NULL DEFAULT 'multi',
			  question_question text NULL,
			  question_answers text NULL,
			  question_data_answers text NULL,
			  question_correct_answer VARCHAR(300) NOT NULL,
			  question_answer_type VARCHAR(50) NOT NULL DEFAULT '',
			  question_answer_hint text NULL,
			  question_answer_explanation text NULL,
			  question_image VARCHAR(300) NOT NULL DEFAULT '',
			  question_answer_file_types VARCHAR(300) NOT NULL DEFAULT '',
			  question_usage_count int(11) UNSIGNED DEFAULT 0,
			  question_expanded_count int(11) UNSIGNED DEFAULT 1,
			  question_multi_random_enable int(2) UNSIGNED DEFAULT 0,
			  question_multi_random_count  int(4) UNSIGNED DEFAULT 5,
			  PRIMARY KEY  (question_id)
			) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
	WPCW_database_installTable( $wpcwdb->quiz_qs, $SQL, $upgradeNow );
	$SQL = "CREATE TABLE $wpcwdb->user_progress_quiz (
			  user_id int(11) NOT NULL,
			  unit_id int(11) NOT NULL,
			  quiz_id bigint(20) NOT NULL,
			  quiz_attempt_id int(11) NOT NULL DEFAULT '0',
			  quiz_completed_date datetime NOT NULL,
			  quiz_started_date datetime NOT NULL,
			  quiz_correct_questions int(11) unsigned NOT NULL,
			  quiz_grade FLOAT(8,2) NOT NULL DEFAULT '-1',
			  quiz_question_total int(11) unsigned NOT NULL,
			  quiz_data text NULL,
			  quiz_is_latest VARCHAR(50) DEFAULT 'latest',
			  quiz_needs_marking int(11) unsigned NOT NULL DEFAULT '0',
			  quiz_needs_marking_list TEXT NULL,
			  quiz_next_step_type VARCHAR(50) DEFAULT '',
			  quiz_next_step_msg TEXT DEFAULT '',
			  quiz_paging_status VARCHAR(20) NOT NULL DEFAULT 'complete',
			  quiz_paging_next_q int(11) NOT NULL DEFAULT 0,
			  quiz_paging_incomplete int(11) NOT NULL DEFAULT 0,
			  quiz_completion_time_seconds BIGINT NOT NULL DEFAULT 0,
			  UNIQUE KEY unique_progress_item (user_id,unit_id,quiz_id,quiz_attempt_id)
			) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
	WPCW_database_installTable( $wpcwdb->user_progress_quiz, $SQL, $upgradeNow );
	$SQL = "CREATE TABLE $wpcwdb->map_member_levels (
			  	course_id int(11) NOT NULL,
  				member_level_id varchar(100) NOT NULL,
  				UNIQUE KEY course_id (course_id,member_level_id)
			) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
	WPCW_database_installTable( $wpcwdb->map_member_levels, $SQL, $upgradeNow );
	$SQL = "CREATE TABLE $wpcwdb->certificates (
			  cert_user_id int(11) NOT NULL,
			  cert_course_id int(11) NOT NULL,
			  cert_access_key varchar(50) NOT NULL,
			  cert_generated datetime NOT NULL,
			  UNIQUE KEY cert_user_id (cert_user_id,cert_course_id)
			) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
	WPCW_database_installTable( $wpcwdb->certificates, $SQL, $upgradeNow );
	$SQL = "CREATE TABLE $wpcwdb->question_tags (
				question_tag_id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
				question_tag_name varchar(150) NOT NULL,
				question_tag_usage int(11) unsigned NOT NULL,
				question_tag_author bigint(20) unsigned NOT NULL default '0',
				PRIMARY KEY  (question_tag_id)
			) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
	WPCW_database_installTable( $wpcwdb->question_tags, $SQL, $upgradeNow );
	$SQL = "CREATE TABLE $wpcwdb->question_tag_mapping (
				question_id bigint(20) unsigned NOT NULL,
				tag_id bigint(20) unsigned NOT NULL,
				UNIQUE KEY question_tag_id (question_id,tag_id)
			) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
	WPCW_database_installTable( $wpcwdb->question_tag_mapping, $SQL, $upgradeNow );
	$SQL = "CREATE TABLE $wpcwdb->quiz_qs_mapping (
				parent_quiz_id bigint(20) unsigned NULL,
				question_id bigint(20) unsigned NOT NULL,
				question_order int(11) unsigned NOT NULL DEFAULT '0',
				UNIQUE KEY question_assoc_id (parent_quiz_id,question_id)
			) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
	WPCW_database_installTable( $wpcwdb->quiz_qs_mapping, $SQL, $upgradeNow );
	$SQL = "CREATE TABLE $wpcwdb->question_rand_lock (
				question_user_id int(11) unsigned NOT NULL,
				rand_question_id int(11) unsigned NOT NULL,
				parent_unit_id int(11) unsigned NOT NULL,
				question_selection_list text NOT NULL,
				UNIQUE KEY wpcw_question_rand_lock (question_user_id,rand_question_id)
			) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
	WPCW_database_installTable( $wpcwdb->question_rand_lock, $SQL, $upgradeNow );
	$SQL = "CREATE TABLE $wpcwdb->quiz_feedback (
			  	qfeedback_id int(11) unsigned NOT NULL AUTO_INCREMENT,
  				qfeedback_tag_id bigint(20) unsigned NOT NULL,
  				qfeedback_quiz_id int(1) unsigned NOT NULL,
  				qfeedback_summary varchar(300) NOT NULL,
  				qfeedback_score_type varchar(20) NOT NULL DEFAULT 'below',
  				qfeedback_score_grade int(11) unsigned NOT NULL DEFAULT '50',
  				qfeedback_message text NOT NULL,
  				PRIMARY KEY  (qfeedback_id)
			) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
	WPCW_database_installTable( $wpcwdb->quiz_feedback, $SQL, $upgradeNow );
	$SQL = "CREATE TABLE $wpcwdb->queue_dripfeed (
			  	queue_id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  				queue_unit_id int(11) unsigned NOT NULL,
  				queue_course_id int(11) unsigned NOT NULL,
  				queue_user_id int(11) NOT NULL,
  				queue_trigger_date datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  				queue_enqueued_date datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  				PRIMARY KEY  (queue_id)
			) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
	WPCW_database_installTable( $wpcwdb->queue_dripfeed, $SQL, $upgradeNow );
	delete_option( 'WPCW_version' );
	update_option( 'wpcw_plugin_version', WPCW_VERSION );
	update_option( 'wpcw_db_version', WPCW_DB_VERSION );
}
function WPCW_database_upgradeTables ( $ installedVersion , $ forceUpgrade , $ showErrors = false ) { global $ wpdb , $ wpcwdb ; if ( $ showErrors ) { $ wpdb -> show_errors ( ) ; } $ upgradeNow = true ; $ SQL = " CREATE TABLE  $ wpcwdb -> courses  (
			  course_id int(11) unsigned NOT NULL AUTO_INCREMENT,
			  course_title varchar(150) NOT NULL,
			  course_desc text NULL,
			  course_author bigint(20) unsigned NOT NULL default '0',
			  course_opt_completion_wall varchar(20) NOT NULL,
			  course_opt_use_certificate varchar(20) NOT NULL DEFAULT 'no_certs',
			  course_opt_user_access varchar(20) NOT NULL,
			  course_unit_count int(11) unsigned NULL DEFAULT '0',
			  course_from_name varchar(150) NOT NULL,
			  course_from_email varchar(150) NOT NULL,
			  course_to_email varchar(150) NOT NULL,
			  course_opt_prerequisites longtext NOT NULL,
			  course_message_unit_complete text NULL,
			  course_message_course_complete text NULL,
			  course_message_unit_not_logged_in text NULL,
			  course_message_unit_pending text NULL,
			  course_message_unit_no_access text NULL,
			  course_message_prerequisite_not_met text NULL,
			  course_message_unit_not_yet text NULL,
			  course_message_unit_not_yet_dripfeed text NULL,
			  course_message_quiz_open_grading_blocking text NULL,
			  course_message_quiz_open_grading_non_blocking text NULL,
			  email_complete_module_option_admin varchar(20) NOT NULL,
			  email_complete_module_option varchar(20) NOT NULL,
			  email_complete_module_subject varchar(300) NOT NULL,
			  email_complete_module_body text NULL,
			  email_complete_course_option_admin varchar(20) NOT NULL,
			  email_complete_course_option varchar(20) NOT NULL,
			  email_complete_course_subject varchar(300) NOT NULL,
			  email_complete_course_body text NULL,
			  email_quiz_grade_option varchar(20) NOT NULL,
			  email_quiz_grade_subject varchar(300) NOT NULL,
			  email_quiz_grade_body text NULL,
			  email_complete_course_grade_summary_subject varchar(300) NOT NULL,
			  email_complete_course_grade_summary_body text NULL,
			  email_unit_unlocked_subject varchar(300) NOT NULL,
			  email_unit_unlocked_body text NULL,
			  cert_signature_type varchar(20) NOT NULL DEFAULT 'text',
			  cert_sig_text varchar(300) NOT NULL,
			  cert_sig_image_url varchar(300) NOT NULL DEFAULT  '',
			  cert_logo_enabled varchar(20) NOT NULL DEFAULT 'no_cert_logo',
			  cert_logo_url varchar(300) NOT NULL DEFAULT '',
			  cert_background_type varchar(20) NOT NULL DEFAULT 'use_default',
			  cert_background_custom_url varchar(300) NOT NULL DEFAULT  '',
			  PRIMARY KEY  (course_id)
			) ENGINE=InnoDB  DEFAULT CHARSET=utf8 " ; WPCW_database_installTable ( $ wpcwdb -> courses , $ SQL , $ upgradeNow ) ; $ SQL = " CREATE TABLE  $ wpcwdb -> modules  (
			  module_id int(11) unsigned NOT NULL AUTO_INCREMENT,
			  parent_course_id int(11) unsigned NOT NULL DEFAULT '0',
			  module_author bigint(20) unsigned NOT NULL default '0',
			  module_title varchar(150) NOT NULL,
			  module_desc text NULL,
			  module_order int(11) unsigned NOT NULL DEFAULT '10000',
			  module_number int(11) unsigned NOT NULL DEFAULT '0',
			  PRIMARY KEY  (module_id)
			) ENGINE=InnoDB  DEFAULT CHARSET=utf8; " ; WPCW_database_installTable ( $ wpcwdb -> modules , $ SQL , $ upgradeNow ) ; $ SQL = " CREATE TABLE  $ wpcwdb -> units_meta  (
			  unit_id int(11) unsigned NOT NULL,
			  parent_module_id int(11) unsigned NOT NULL DEFAULT '0',
			  parent_course_id int(11) unsigned NOT NULL DEFAULT '0',
			  unit_author bigint(20) unsigned NOT NULL default '0',
			  unit_order int(11) unsigned NOT NULL DEFAULT '0',
			  unit_number int(11) unsigned NOT NULL DEFAULT '0',
			  unit_drip_type varchar(50) NOT NULL DEFAULT '',
			  unit_drip_date datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
			  unit_drip_interval int(11) NOT NULL DEFAULT '432000',
			  unit_drip_interval_type varchar(15) NOT NULL DEFAULT 'interval_days',
			  PRIMARY KEY  (unit_id)
			) ENGINE=InnoDB DEFAULT CHARSET=utf8; " ; WPCW_database_installTable ( $ wpcwdb -> units_meta , $ SQL , $ upgradeNow ) ; $ SQL = " CREATE TABLE  $ wpcwdb -> user_courses  (
			  user_id int(11) unsigned NOT NULL,
			  course_id int(11) unsigned NOT NULL,
			  course_progress int(11) NOT NULL DEFAULT '0',
			  course_final_grade_sent VARCHAR(30) NOT NULL DEFAULT '',
			  course_enrolment_date datetime DEFAULT '0000-00-00 00:00:00',
			  UNIQUE KEY user_id (user_id,course_id)
			) ENGINE=InnoDB DEFAULT CHARSET=utf8; " ; WPCW_database_installTable ( $ wpcwdb -> user_courses , $ SQL , $ upgradeNow ) ; $ SQL = " CREATE TABLE  $ wpcwdb -> user_progress  (
			  user_id int(11) unsigned NOT NULL,
			  unit_id int(11) unsigned NOT NULL,
			  unit_completed_date datetime DEFAULT NULL,
			  unit_completed_status varchar(20) NOT NULL,
			  PRIMARY KEY  (user_id,unit_id)
			) ENGINE=InnoDB DEFAULT CHARSET=utf8; " ; WPCW_database_installTable ( $ wpcwdb -> user_progress , $ SQL , $ upgradeNow ) ; $ SQL = " CREATE TABLE  $ wpcwdb -> quiz  (
			  quiz_id int(11) unsigned NOT NULL AUTO_INCREMENT,
			  quiz_title varchar(150) NOT NULL,
			  quiz_desc text NULL,
			  quiz_author bigint(20) unsigned NOT NULL default '0',
			  parent_unit_id int(11) unsigned NOT NULL DEFAULT '0',
			  parent_course_id int(11) NOT NULL DEFAULT '0',
			  quiz_type varchar(15) NOT NULL,
			  quiz_pass_mark int(11) NOT NULL DEFAULT '0',
			  quiz_show_answers varchar(15) NOT NULL DEFAULT 'no_answers',
			  quiz_show_survey_responses varchar(15) NOT NULL DEFAULT 'no_responses',
			  quiz_attempts_allowed int(11) NOT NULL DEFAULT '-1',
			  show_answers_settings VARCHAR(500) NOT NULL DEFAULT '',
			  quiz_paginate_questions VARCHAR(15) NOT NULL DEFAULT 'no_paging',
			  quiz_paginate_questions_settings VARCHAR(500) NOT NULL DEFAULT '',
			  quiz_timer_mode varchar(25) NOT NULL DEFAULT 'no_timer',
			  quiz_timer_mode_limit int(11) unsigned NOT NULL DEFAULT '15',
			  quiz_results_downloadable varchar(10) NOT NULL DEFAULT 'on',
			  quiz_results_by_tag varchar(10) NOT NULL DEFAULT 'on',
			  quiz_results_by_timer varchar(10) NOT NULL DEFAULT 'on',
			  quiz_recommended_score varchar(20) NOT NULL DEFAULT 'no_recommended',
			  show_recommended_percentage int(10) unsigned NOT NULL DEFAULT 50,
			  PRIMARY KEY  (quiz_id)
			) ENGINE=InnoDB DEFAULT CHARSET=utf8; " ; WPCW_database_installTable ( $ wpcwdb -> quiz , $ SQL , $ upgradeNow ) ; $ SQL = " CREATE TABLE  $ wpcwdb -> quiz_qs  (
			  question_id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
			  question_author bigint(20) unsigned NOT NULL default '0',
			  question_type VARCHAR(20) NOT NULL DEFAULT 'multi',
			  question_question text NULL,
			  question_answers text NULL,
			  question_data_answers text NULL,
			  question_correct_answer VARCHAR(300) NOT NULL,
			  question_answer_type VARCHAR(50) NOT NULL DEFAULT '',
			  question_answer_hint text NULL,
			  question_answer_explanation text NULL,
			  question_image VARCHAR(300) NOT NULL DEFAULT '',
			  question_answer_file_types VARCHAR(300) NOT NULL DEFAULT '',
			  question_usage_count int(11) UNSIGNED DEFAULT 0,
			  question_expanded_count int(11) UNSIGNED DEFAULT 1,
			  question_multi_random_enable int(2) UNSIGNED DEFAULT 0,
			  question_multi_random_count  int(4) UNSIGNED DEFAULT 5,
			  PRIMARY KEY  (question_id)
			) ENGINE=InnoDB DEFAULT CHARSET=utf8; " ; WPCW_database_installTable ( $ wpcwdb -> quiz_qs , $ SQL , $ upgradeNow ) ; $ SQL = " CREATE TABLE  $ wpcwdb -> user_progress_quiz  (
			  user_id int(11) NOT NULL,
			  unit_id int(11) NOT NULL,
			  quiz_id bigint(20) NOT NULL,
			  quiz_attempt_id int(11) NOT NULL DEFAULT '0',
			  quiz_completed_date datetime NOT NULL,
			  quiz_started_date datetime NOT NULL,
			  quiz_correct_questions int(11) unsigned NOT NULL,
			  quiz_grade FLOAT(8,2) NOT NULL DEFAULT '-1',
			  quiz_question_total int(11) unsigned NOT NULL,
			  quiz_data text NULL,
			  quiz_is_latest VARCHAR(50) DEFAULT 'latest',
			  quiz_needs_marking int(11) unsigned NOT NULL DEFAULT '0',
			  quiz_needs_marking_list TEXT NULL,
			  quiz_next_step_type VARCHAR(50) DEFAULT '',
			  quiz_next_step_msg TEXT DEFAULT '',
			  quiz_paging_status VARCHAR(20) NOT NULL DEFAULT 'complete',
			  quiz_paging_next_q int(11) NOT NULL DEFAULT 0,
			  quiz_paging_incomplete int(11) NOT NULL DEFAULT 0,
			  quiz_completion_time_seconds BIGINT NOT NULL DEFAULT 0,
			  UNIQUE KEY unique_progress_item (user_id,unit_id,quiz_id,quiz_attempt_id)
			) ENGINE=InnoDB DEFAULT CHARSET=utf8; " ; WPCW_database_installTable ( $ wpcwdb -> user_progress_quiz , $ SQL , $ upgradeNow ) ; $ SQL = " CREATE TABLE  $ wpcwdb -> map_member_levels  (
			  	course_id int(11) NOT NULL,
  				member_level_id varchar(100) NOT NULL,
  				UNIQUE KEY course_id (course_id,member_level_id)
			) ENGINE=InnoDB DEFAULT CHARSET=utf8; " ; WPCW_database_installTable ( $ wpcwdb -> map_member_levels , $ SQL , $ upgradeNow ) ; $ SQL = " CREATE TABLE  $ wpcwdb -> certificates  (
			  cert_user_id int(11) NOT NULL,
			  cert_course_id int(11) NOT NULL,
			  cert_access_key varchar(50) NOT NULL,
			  cert_generated datetime NOT NULL,
			  UNIQUE KEY cert_user_id (cert_user_id,cert_course_id)
			) ENGINE=InnoDB DEFAULT CHARSET=utf8; " ; WPCW_database_installTable ( $ wpcwdb -> certificates , $ SQL , $ upgradeNow ) ; $ SQL = " CREATE TABLE  $ wpcwdb -> question_tags  (
				question_tag_id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
				question_tag_name varchar(150) NOT NULL,
				question_tag_usage int(11) unsigned NOT NULL,
				question_tag_author bigint(20) unsigned NOT NULL default '0',
				PRIMARY KEY  (question_tag_id)
			) ENGINE=InnoDB DEFAULT CHARSET=utf8; " ; WPCW_database_installTable ( $ wpcwdb -> question_tags , $ SQL , $ upgradeNow ) ; $ SQL = " CREATE TABLE  $ wpcwdb -> question_tag_mapping  (
				question_id bigint(20) unsigned NOT NULL,
				tag_id bigint(20) unsigned NOT NULL,
				UNIQUE KEY question_tag_id (question_id,tag_id)
			) ENGINE=InnoDB DEFAULT CHARSET=utf8; " ; WPCW_database_installTable ( $ wpcwdb -> question_tag_mapping , $ SQL , $ upgradeNow ) ; $ SQL = " CREATE TABLE  $ wpcwdb -> quiz_qs_mapping  (
				parent_quiz_id bigint(20) unsigned NULL,
				question_id bigint(20) unsigned NOT NULL,
				question_order int(11) unsigned NOT NULL DEFAULT '0',
				UNIQUE KEY question_assoc_id (parent_quiz_id,question_id)
			) ENGINE=InnoDB DEFAULT CHARSET=utf8; " ; WPCW_database_installTable ( $ wpcwdb -> quiz_qs_mapping , $ SQL , $ upgradeNow ) ; $ SQL = " CREATE TABLE  $ wpcwdb -> question_rand_lock  (
				question_user_id int(11) unsigned NOT NULL,
				rand_question_id int(11) unsigned NOT NULL,
				parent_unit_id int(11) unsigned NOT NULL,
				question_selection_list text NOT NULL,
				UNIQUE KEY wpcw_question_rand_lock (question_user_id,rand_question_id)
			) ENGINE=InnoDB DEFAULT CHARSET=utf8; " ; WPCW_database_installTable ( $ wpcwdb -> question_rand_lock , $ SQL , $ upgradeNow ) ; $ SQL = " CREATE TABLE  $ wpcwdb -> quiz_feedback  (
			  	qfeedback_id int(11) unsigned NOT NULL AUTO_INCREMENT,
  				qfeedback_tag_id bigint(20) unsigned NOT NULL,
  				qfeedback_quiz_id int(1) unsigned NOT NULL,
  				qfeedback_summary varchar(300) NOT NULL,
  				qfeedback_score_type varchar(20) NOT NULL DEFAULT 'below',
  				qfeedback_score_grade int(11) unsigned NOT NULL DEFAULT '50',
  				qfeedback_message text NOT NULL,
  				PRIMARY KEY  (qfeedback_id)
			) ENGINE=InnoDB DEFAULT CHARSET=utf8; " ; WPCW_database_installTable ( $ wpcwdb -> quiz_feedback , $ SQL , $ upgradeNow ) ; $ SQL = " CREATE TABLE  $ wpcwdb -> queue_dripfeed  (
			  	queue_id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  				queue_unit_id int(11) unsigned NOT NULL,
  				queue_course_id int(11) unsigned NOT NULL,
  				queue_user_id int(11) NOT NULL,
  				queue_trigger_date datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  				queue_enqueued_date datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  				PRIMARY KEY  (queue_id)
			) ENGINE=InnoDB DEFAULT CHARSET=utf8; " ; WPCW_database_installTable ( $ wpcwdb -> queue_dripfeed , $ SQL , $ upgradeNow ) ; delete_option ( 'WPCW_version' ) ; update_option ( 'wpcw_plugin_version' , WPCW_VERSION ) ; update_option ( 'wpcw_db_version' , WPCW_DB_VERSION ) ; }
Function to upgrade the database tables.
Function to upgrade the database tables .
// globals // Show errors if debugging // Always upgrade tables. Conditionally execute any other table changes. // Courses Table // Modules Table // Units Meta Table // User Courses Allocations Table // User Progress Table // Quizzes Table // Quiz - Questions // Quiz - User Progress // Mapping of membership levels // Mapping of certificates // Questions - Tags // Questions - Tag Mappings // Questions/Quizzes - Mappings // Random Questions - Lock selections to a user so that they don't see different variations if refreshed. // List of quiz custom feedback // Queue used for notifying trainees that the next unit is available. // Update settings once upgrade has happened