| 1 |
<?php |
| 2 |
/* |
| 3 |
*Plugin Name: Watu Quiz |
| 4 |
*Plugin URI: http://calendarscripts.info/watu-wordpress.html |
| 5 |
*Description: Create exams and quizzes and display the result immediately after the user takes the exam. Watu for Wordpress is a light version of <a href="http://calendarscripts.info/watupro/" target="_blank">WatuPRO</a>. Check it if you want to run fully featured exams with data exports, student logins, timers, random questions and more. Free support and upgrades are available. Go to <a href="admin.php?page=watu_settings">Watu Settings</a> or <a href="tools.php?page=watu_exams">Manage Your Exams</a> |
| 6 |
|
| 7 |
*Version: 3.4.8 |
| 8 |
*Author: Kiboko Labs |
| 9 |
*License: GPLv2 or later |
| 10 |
*Text domain: watu |
| 11 |
*Domain Path: /languages |
| 12 |
|
| 13 |
This program is free software; you can redistribute it and/or |
| 14 |
modify it under the terms of the GNU General Public License |
| 15 |
as published by the Free Software Foundation; either version 2 |
| 16 |
of the License, or (at your option) any later version. |
| 17 |
|
| 18 |
This program is distributed in the hope that it will be useful, |
| 19 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 |
GNU General Public License for more details. |
| 22 |
|
| 23 |
You should have received a copy of the GNU General Public License |
| 24 |
along with this program; if not, write to the Free Software |
| 25 |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 26 |
*/ |
| 27 |
|
| 28 |
define( 'WATU_PATH', dirname( __FILE__ ) ); |
| 29 |
define( 'WATU_URL', plugin_dir_url( __FILE__ )); |
| 30 |
include( WATU_PATH.'/controllers/exam.php'); |
| 31 |
include( WATU_PATH.'/controllers/questions.php'); |
| 32 |
include( WATU_PATH.'/controllers/takings.php'); |
| 33 |
include( WATU_PATH.'/controllers/ajax.php'); |
| 34 |
include( WATU_PATH.'/controllers/grades.php'); |
| 35 |
include( WATU_PATH.'/controllers/social-sharing.php'); |
| 36 |
include( WATU_PATH.'/models/question.php'); |
| 37 |
include( WATU_PATH.'/lib/functions.php'); |
| 38 |
include( WATU_PATH.'/lib/text-captcha.php'); |
| 39 |
include( WATU_PATH."/models/exam.php"); |
| 40 |
include( WATU_PATH.'/controllers/shortcodes.php'); |
| 41 |
|
| 42 |
function watu_init() { |
| 43 |
global $wpdb; |
| 44 |
|
| 45 |
load_plugin_textdomain('watu', false, dirname( plugin_basename( __FILE__ )).'/langs/' ); |
| 46 |
|
| 47 |
if(get_option('watu_debug_mode')) { |
| 48 |
$wpdb->show_errors(); |
| 49 |
if(!defined('DIEONDBERROR')) define( 'DIEONDBERROR', true ); |
| 50 |
} |
| 51 |
|
| 52 |
$version = get_bloginfo('version'); |
| 53 |
if($version <= 3.3) add_action('wp_enqueue_scripts', 'watu_vc_scripts'); |
| 54 |
add_action('admin_enqueue_scripts', 'watu_vc_scripts'); |
| 55 |
add_action('wp_enqueue_scripts', 'watu_vc_jquery'); |
| 56 |
|
| 57 |
add_shortcode( 'WATU', 'watu_shortcode' ); |
| 58 |
add_shortcode( 'watu', 'watu_shortcode' ); |
| 59 |
add_shortcode( 'watushare-buttons', array('WatuSharing', 'display') ); |
| 60 |
add_shortcode( 'watu-basic-chart', 'watu_basic_chart' ); |
| 61 |
add_shortcode( 'watu-takings', 'watu_shortcode_takings' ); |
| 62 |
add_shortcode( 'watu-userinfo', array('WatuShortcodes', 'userinfo') ); |
| 63 |
|
| 64 |
// table names as constants |
| 65 |
define('WATU_EXAMS', $wpdb->prefix.'watu_master'); |
| 66 |
define('WATU_QUESTIONS', $wpdb->prefix.'watu_question'); |
| 67 |
define('WATU_ANSWERS', $wpdb->prefix.'watu_answer'); |
| 68 |
define('WATU_GRADES', $wpdb->prefix.'watu_grading'); |
| 69 |
define('WATU_TAKINGS', $wpdb->prefix.'watu_takings'); |
| 70 |
define('WATU_QCATS', $wpdb->prefix.'watu_qcats'); |
| 71 |
|
| 72 |
// which filter to use |
| 73 |
$content_filter = get_option('watu_use_the_content') ? 'the_content' : 'watu_content'; |
| 74 |
define('WATU_CONTENT_FILTER', $content_filter); |
| 75 |
|
| 76 |
// word used for quiz |
| 77 |
$quiz_word = get_option('watu_quiz_word'); |
| 78 |
$quiz_word = $quiz_word ? $quiz_word : __('quiz', 'watu'); |
| 79 |
$quiz_word_plural = get_option('watu_quiz_word_plural'); |
| 80 |
$quiz_word_plural = $quiz_word_plural ? $quiz_word_plural : __('quizzes', 'watu'); |
| 81 |
define('WATU_QUIZ_WORD', $quiz_word); |
| 82 |
define('WATU_QUIZ_WORD_PLURAL', $quiz_word_plural); |
| 83 |
|
| 84 |
// handle tablepress |
| 85 |
if(class_exists('TablePress')) { |
| 86 |
//TablePress::$controller = TablePress::load_controller( 'frontend' ); |
| 87 |
//TablePress::$controller->init_shortcodes(); |
| 88 |
} |
| 89 |
|
| 90 |
// add_filter( 'watu_content', 'watu_autop' ); |
| 91 |
add_filter( 'watu_content', 'wptexturize' ); |
| 92 |
// add_filter( 'watu_content', 'convert_smilies' ); |
| 93 |
add_filter( 'watu_content', 'convert_chars' ); |
| 94 |
add_filter( 'watu_content', 'shortcode_unautop' ); |
| 95 |
add_filter( 'watu_content', 'do_shortcode' ); |
| 96 |
|
| 97 |
// Compatibility with specific plugins |
| 98 |
// qTranslate |
| 99 |
if(function_exists('qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage')) add_filter('watu_content', 'qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage'); |
| 100 |
// WP QuickLaTeX |
| 101 |
if(function_exists('quicklatex_parser')) add_filter( 'watu_content', 'quicklatex_parser', 7); |
| 102 |
// handle the MoolaMojo integration |
| 103 |
add_action('watu_exam_submitted_detailed', 'watu_taking_transfer_moola', 10, 5); |
| 104 |
|
| 105 |
$version = get_option('watu_version'); |
| 106 |
if(version_compare($version, '2.88') == -1) watu_activate(true); |
| 107 |
|
| 108 |
add_action('admin_notices', 'watu_admin_notice'); |
| 109 |
} |
| 110 |
|
| 111 |
function watu_autop($content) { |
| 112 |
//return wpautop($content, false); |
| 113 |
return nl2br($content); |
| 114 |
} |
| 115 |
|
| 116 |
/** |
| 117 |
* Add a new menu under Manage, visible for all users with template viewing level. |
| 118 |
*/ |
| 119 |
add_action( 'admin_menu', 'watu_add_menu_links' ); |
| 120 |
add_action ( 'watu_exam', 'watu_exam' ); |
| 121 |
function watu_add_menu_links() { |
| 122 |
global $wp_version, $_registered_pages; |
| 123 |
$view_level = current_user_can('watu_manage') ? 'watu_manage' : 'manage_options'; |
| 124 |
|
| 125 |
|
| 126 |
add_menu_page(sprintf(__('Watu %s', 'watu'), ucfirst(WATU_QUIZ_WORD_PLURAL)), sprintf(__('Watu %s', 'watu'), ucfirst(WATU_QUIZ_WORD_PLURAL)), $view_level, 'watu_exams', 'watu_exams'); |
| 127 |
add_submenu_page('watu_exams', __('Settings', 'watu'), __('Settings', 'watu'), $view_level , 'watu_options', 'watu_options'); |
| 128 |
add_submenu_page('watu_exams', __('Social Sharing', 'watu'), __('Social Sharing', 'watu'), $view_level , 'watu_social_sharing', array('WatuSharing', 'options')); |
| 129 |
add_submenu_page('watu_exams', __('Help & Support', 'watu'), __('Help & Support', 'watu'), $view_level , 'watu_help', 'watu_help'); |
| 130 |
|
| 131 |
do_action('watu_admin_menu'); |
| 132 |
|
| 133 |
// hidden pages |
| 134 |
add_submenu_page("", sprintf(__('Add/Edit %s', 'watu'), ucfirst(WATU_QUIZ_WORD)), sprintf(__('Add/Edit %s', 'watu'), ucfirst(WATU_QUIZ_WORD)), $view_level , 'watu_exam', 'watu_exam'); |
| 135 |
|
| 136 |
add_submenu_page('', __('Manage Questions', 'watu'), __('Manage Questions', 'watu'), $view_level , 'watu_questions', 'watu_questions'); |
| 137 |
add_submenu_page('', __('Add/Edit Question', 'watu'), __('Add/Edit Question', 'watu'), $view_level , 'watu_question', 'watu_question'); |
| 138 |
add_submenu_page('', __('Manage Grades', 'watu'), __('Manage Grades', 'watu'), $view_level , 'watu_grades', 'watu_grades'); |
| 139 |
add_submenu_page('', sprintf(__('%s submissions', 'watu'), ucfirst(WATU_QUIZ_WORD)), sprintf(__('%s submissions', 'watu'), ucfirst(WATU_QUIZ_WORD)), $view_level, 'watu_takings', 'watu_takings'); |
| 140 |
add_submenu_page('', __('Import Questions', 'watu'), __('Import Questions', 'watu'), $view_level, 'watu_import_questions', 'watu_import_questions'); |
| 141 |
|
| 142 |
} |
| 143 |
|
| 144 |
function watu_options() { |
| 145 |
if ( function_exists('current_user_can') && !current_user_can('manage_options') ) die(__("Your are not allowed to to perform this operation", 'watu')); |
| 146 |
if (! user_can_access_admin_page()) wp_die( __('You do not have sufficient permissions to access this page', 'watu') ); |
| 147 |
|
| 148 |
require(WATU_PATH.'/options.php'); |
| 149 |
} |
| 150 |
|
| 151 |
/** |
| 152 |
* This will scan all the content pages that WordPress outputs for our special code. If the code is found, it will replace the requested quiz. |
| 153 |
*/ |
| 154 |
function watu_shortcode( $attr ) { |
| 155 |
$exam_id = $attr[0] ?? 0; |
| 156 |
|
| 157 |
$contents = ''; |
| 158 |
if(!is_numeric($exam_id)) return $contents; |
| 159 |
|
| 160 |
watu_vc_scripts(); |
| 161 |
|
| 162 |
// submitting without ajax? |
| 163 |
if(!empty($_POST['no_ajax']) and !empty($exam->no_ajax)) { |
| 164 |
if (!check_admin_referer('watu_submit_nonce', 'watu_nonce')) { |
| 165 |
wp_die(__('Security check failed.', 'watu')); |
| 166 |
} |
| 167 |
require(WATU_PATH."/show_exam.php"); |
| 168 |
$contents = ob_get_clean(); |
| 169 |
$contents = apply_filters('watu_content', $contents); |
| 170 |
return $contents; |
| 171 |
} |
| 172 |
|
| 173 |
ob_start(); |
| 174 |
include(WATU_PATH . '/controllers/show_exam.php'); |
| 175 |
$contents = ob_get_contents(); |
| 176 |
ob_end_clean(); |
| 177 |
|
| 178 |
return $contents; |
| 179 |
} |
| 180 |
|
| 181 |
add_action('activate_watu/watu.php','watu_activate'); |
| 182 |
function watu_activate($update = false) { |
| 183 |
global $wpdb; |
| 184 |
|
| 185 |
$wpdb-> show_errors(); |
| 186 |
$collation = $wpdb->get_charset_collate(); |
| 187 |
$version = get_option('watu_version'); |
| 188 |
if(!$update) watu_init(); |
| 189 |
|
| 190 |
// Initial options. |
| 191 |
update_option('watu_show_answers', 1, false); |
| 192 |
update_option('watu_single_page', 0, false); |
| 193 |
update_option('watu_answer_type', 'radio', false); |
| 194 |
|
| 195 |
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
| 196 |
|
| 197 |
if($wpdb->get_var("SHOW TABLES LIKE '".WATU_EXAMS."'") != WATU_EXAMS) { |
| 198 |
$sql = "CREATE TABLE `".WATU_EXAMS."`( |
| 199 |
ID int(11) unsigned NOT NULL auto_increment, |
| 200 |
name varchar(50) NOT NULL DEFAULT '', |
| 201 |
description mediumtext NOT NULL, |
| 202 |
final_screen mediumtext NOT NULL, |
| 203 |
added_on datetime NOT NULL DEFAULT '1900-01-01', |
| 204 |
PRIMARY KEY (ID) |
| 205 |
) $collation "; |
| 206 |
$wpdb->query($sql); |
| 207 |
} |
| 208 |
|
| 209 |
if($wpdb->get_var("SHOW TABLES LIKE '".WATU_QUESTIONS."'") != WATU_QUESTIONS) { |
| 210 |
$sql = "CREATE TABLE ".WATU_QUESTIONS." ( |
| 211 |
ID int(11) unsigned NOT NULL auto_increment, |
| 212 |
exam_id int(11) unsigned NOT NULL DEFAULT 0, |
| 213 |
question mediumtext NOT NULL, |
| 214 |
answer_type char(15) NOT NULL DEFAULT '', |
| 215 |
sort_order int(3) NOT NULL default 0, |
| 216 |
PRIMARY KEY (ID), |
| 217 |
KEY quiz_id (exam_id) |
| 218 |
) $collation"; |
| 219 |
$wpdb->query($sql); |
| 220 |
} |
| 221 |
|
| 222 |
if($wpdb->get_var("SHOW TABLES LIKE '".WATU_ANSWERS."'") != WATU_ANSWERS) { |
| 223 |
$sql = "CREATE TABLE ".WATU_ANSWERS." ( |
| 224 |
ID int(11) unsigned NOT NULL auto_increment, |
| 225 |
question_id int(11) unsigned NOT NULL, |
| 226 |
answer TEXT, |
| 227 |
correct enum('0','1') NOT NULL default '0', |
| 228 |
point DECIMAL(8,2) NOT NULL default '0.00', |
| 229 |
sort_order int(3) NOT NULL default 0, |
| 230 |
PRIMARY KEY (ID) |
| 231 |
) $collation"; |
| 232 |
$wpdb->query($sql); |
| 233 |
} |
| 234 |
|
| 235 |
if($wpdb->get_var("SHOW TABLES LIKE '".WATU_GRADES."'") != WATU_GRADES) { |
| 236 |
$sql = "CREATE TABLE `".WATU_GRADES."` ( |
| 237 |
`ID` int(11) NOT NULL AUTO_INCREMENT, |
| 238 |
`exam_id` int(11) NOT NULL DEFAULT 0, |
| 239 |
`gtitle` varchar (255) NOT NULL DEFAULT '', |
| 240 |
`gdescription` mediumtext NOT NULL, |
| 241 |
`gfrom` DECIMAL(8,2) NOT NULL default '0.00', |
| 242 |
`gto` DECIMAL(8,2) NOT NULL default '0.00', |
| 243 |
PRIMARY KEY (`ID`) |
| 244 |
) $collation"; |
| 245 |
$wpdb->query($sql); |
| 246 |
} |
| 247 |
|
| 248 |
if($wpdb->get_var("SHOW TABLES LIKE '".WATU_TAKINGS."'") != WATU_TAKINGS) { |
| 249 |
$sql = "CREATE TABLE `".WATU_TAKINGS."` ( |
| 250 |
`ID` int(11) NOT NULL AUTO_INCREMENT, |
| 251 |
`exam_id` int(11) NOT NULL DEFAULT 0, |
| 252 |
`user_id` int(11) NOT NULL DEFAULT 0, |
| 253 |
`ip` varchar(20) NOT NULL DEFAULT '', |
| 254 |
`date` DATE NOT NULL DEFAULT '1900-01-01', |
| 255 |
`points` INT NOT NULL DEFAULT 0, |
| 256 |
`grade_id` INT UNSIGNED NOT NULL DEFAULT 0, |
| 257 |
PRIMARY KEY (`ID`) |
| 258 |
) $collation"; |
| 259 |
$wpdb->query($sql); |
| 260 |
} |
| 261 |
|
| 262 |
// Question categories |
| 263 |
$sql = "CREATE TABLE " . WATU_QCATS . " ( |
| 264 |
ID int(11) UNSIGNED NOT NULL AUTO_INCREMENT, |
| 265 |
name varchar(255) NOT NULL DEFAULT '', |
| 266 |
PRIMARY KEY (ID) |
| 267 |
) $collation"; |
| 268 |
dbDelta( $sql ); |
| 269 |
|
| 270 |
watu_add_db_fields(array( |
| 271 |
array("name"=>"randomize", "type"=>"TINYINT NOT NULL DEFAULT 0"), |
| 272 |
array("name"=>"single_page", "type"=>"TINYINT NOT NULL DEFAULT 0"), |
| 273 |
array("name"=>"show_answers", "type"=>"TINYINT NOT NULL DEFAULT 100"), |
| 274 |
array("name"=>"require_login", "type"=>"TINYINT NOT NULL DEFAULT 0"), |
| 275 |
array("name"=>"notify_admin", "type"=>"TINYINT NOT NULL DEFAULT 0"), |
| 276 |
array("name"=>"randomize_answers", "type"=>"TINYINT NOT NULL DEFAULT 0"), |
| 277 |
array("name"=>"pull_random", "type"=>"INT UNSIGNED NOT NULL DEFAULT 0"), |
| 278 |
array("name"=>"dont_store_data", "type"=>"TINYINT UNSIGNED NOT NULL DEFAULT 0"), |
| 279 |
array("name"=>"show_prev_button", "type"=>"TINYINT UNSIGNED NOT NULL DEFAULT 0"), |
| 280 |
array("name"=>"dont_display_question_numbers", "type"=>"TINYINT UNSIGNED NOT NULL DEFAULT 0"), |
| 281 |
array("name"=>"require_text_captcha", "type"=>"TINYINT UNSIGNED NOT NULL DEFAULT 0"), |
| 282 |
array("name"=>"email_output", "type"=>"TEXT"), |
| 283 |
array("name"=>"notify_user", "type"=>"TINYINT NOT NULL DEFAULT 0"), |
| 284 |
array("name"=>"notify_email", "type"=>"VARCHAR(255) NOT NULL DEFAULT ''"), |
| 285 |
array("name"=>"take_again", "type"=>"TINYINT NOT NULL DEFAULT 0"), |
| 286 |
array("name"=>"times_to_take", "type"=>"TINYINT NOT NULL DEFAULT 0"), |
| 287 |
array("name"=>"no_ajax", "type"=>"TINYINT NOT NULL DEFAULT 0"), /* don't use Ajax when submitting this quiz */ |
| 288 |
array("name"=>"no_alert_unanswered", "type"=>"TINYINT NOT NULL DEFAULT 0"), /* don't alert users for non-answering optional question */ |
| 289 |
array("name"=>"use_honeypot", "type"=>"TINYINT NOT NULL DEFAULT 0"), |
| 290 |
array("name"=>"save_source_url", "type"=>"TINYINT NOT NULL DEFAULT 0"), |
| 291 |
array("name"=>"advanced_settings", "type"=>"TEXT"), |
| 292 |
array("name"=>"email_subject", "type"=>"TEXT"), |
| 293 |
array("name"=>"is_scheduled", "type"=>"TINYINT UNSIGNED NOT NULL DEFAULT 0"), |
| 294 |
array("name"=>"schedule_from", "type"=>"DATETIME"), |
| 295 |
array("name"=>"schedule_to", "type"=>"DATETIME"), |
| 296 |
), WATU_EXAMS); |
| 297 |
|
| 298 |
watu_add_db_fields(array( |
| 299 |
array("name"=>"redirect_url", "type"=>"VARCHAR(255) NOT NULL DEFAULT ''"), |
| 300 |
array("name" => 'moola', "type" => "INT NOT NULL DEFAULT 0"), // integration with MoolaMojo |
| 301 |
), WATU_GRADES); |
| 302 |
|
| 303 |
// db updates in 1.8 |
| 304 |
if(empty($version) or $version < 1.8) { |
| 305 |
// let all existing exams follow the default option |
| 306 |
$sql = "UPDATE ".WATU_EXAMS." SET single_page = '".get_option('watu_single_page')."'"; |
| 307 |
$wpdb->query($sql); |
| 308 |
} |
| 309 |
|
| 310 |
watu_add_db_fields(array( |
| 311 |
array("name"=>"is_required", "type"=>"TINYINT UNSIGNED NOT NULL DEFAULT 0"), |
| 312 |
array("name"=>"feedback", "type"=>"TEXT"), |
| 313 |
array("name"=>"is_inactive", "type"=>"TINYINT UNSIGNED NOT NULL DEFAULT 0"), |
| 314 |
array("name"=>"is_survey", "type"=>"TINYINT UNSIGNED NOT NULL DEFAULT 0"), |
| 315 |
array("name" => "num_columns", "type" => "TINYINT NOT NULL DEFAULT 0"), // num columns for the choices 1 to 4 |
| 316 |
array("name" => "cat_id", "type" => "INT NOT NULL DEFAULT 0"), |
| 317 |
), WATU_QUESTIONS); |
| 318 |
|
| 319 |
watu_add_db_fields(array( |
| 320 |
array("name"=>"result", "type"=>"TEXT"), |
| 321 |
array("name"=>"snapshot", "type"=>"MEDIUMTEXT"), |
| 322 |
array("name"=>"start_time", "type"=>"DATETIME"), |
| 323 |
array("name"=>"email", "type"=>"VARCHAR(255) NOT NULL DEFAULT ''"), /* when email is given, let's store it */ |
| 324 |
array("name"=>"percent_correct", "type"=>"TINYINT UNSIGNED NOT NULL DEFAULT 0"), |
| 325 |
array("name"=>"source_url", "type"=>"VARCHAR(255) NOT NULL DEFAULT ''"), |
| 326 |
array("name"=>"num_correct", "type"=>"SMALLINT NOT NULL DEFAULT 0"), |
| 327 |
array("name"=>"num_wrong", "type"=>"SMALLINT NOT NULL DEFAULT 0"), |
| 328 |
array("name"=>"num_empty", "type"=>"SMALLINT NOT NULL DEFAULT 0"), |
| 329 |
), WATU_TAKINGS); |
| 330 |
|
| 331 |
// let's change choice and answer fields to TEXT instead of VARCHAR - 2.1.3 |
| 332 |
if(empty($version) or $version < 2.1) { |
| 333 |
// let all existing exams follow the default option |
| 334 |
$sql = "ALTER TABLE ".WATU_ANSWERS." CHANGE answer answer TEXT"; |
| 335 |
$wpdb->query($sql); |
| 336 |
} |
| 337 |
|
| 338 |
$demo_quiz_created = get_option('watu_demo_quiz_created'); |
| 339 |
if($demo_quiz_created != '1') WatuExam :: create_demo(); |
| 340 |
|
| 341 |
// versions before 2.44 had the following text hard-coded. We need to make sure thta the quizzes which were showing results |
| 342 |
// now have it in the "final screen" |
| 343 |
if(!empty($version) and $version < 2.45) { |
| 344 |
$answers_text = "<p>" . __('All the questions in the quiz along with their answers are shown below. Your answers are bolded. The correct answers have a green background while the incorrect ones have a red background.', 'watu') . "</p> %%ANSWERS%%"; |
| 345 |
$wpdb->query("UPDATE ".WATU_EXAMS." SET final_screen = CONCAT(final_screen, '$answers_text') WHERE show_answers=1"); |
| 346 |
} |
| 347 |
|
| 348 |
// let all quizzes prior to DB version 2.49 have dont_display_question_numbers = 1 because this is how it was |
| 349 |
if(!empty($version) and $version < 2.49) { |
| 350 |
$wpdb->query("UPDATE ".WATU_EXAMS." SET dont_display_question_numbers=1"); |
| 351 |
} |
| 352 |
|
| 353 |
// let's make all "require_login" quizzes created previously to have take_again=1 to avoid sudden change |
| 354 |
if(!empty($version) and $version < 2.56) { |
| 355 |
$wpdb->query("UPDATE ".WATU_EXAMS." SET take_again=1 WHERE require_login=1"); |
| 356 |
} |
| 357 |
|
| 358 |
// change points in answers & grades to decimals |
| 359 |
if(!empty($version) and $version < 2.64) { |
| 360 |
$wpdb->query("ALTER TABLE ".WATU_ANSWERS." CHANGE `point` `point` DECIMAL(8,2) NOT NULL DEFAULT '0.00'"); |
| 361 |
$wpdb->query("ALTER TABLE ".WATU_GRADES." CHANGE `gfrom` `gfrom` DECIMAL(8,2) NOT NULL DEFAULT '0.00', |
| 362 |
CHANGE `gto` `gto` DECIMAL(8,2) NOT NULL DEFAULT '0.00'"); |
| 363 |
} |
| 364 |
|
| 365 |
// add indexes |
| 366 |
if(version_compare($version, '2.88') == -1) { |
| 367 |
$wpdb->query("ALTER TABLE ".WATU_ANSWERS." ADD INDEX `quesiton_id` (`question_id`);"); |
| 368 |
$wpdb->query("ALTER TABLE ".WATU_GRADES." ADD INDEX `quiz_and_criteria` (`exam_id`, `gfrom`, `gto`);"); |
| 369 |
$wpdb->query("ALTER TABLE ".WATU_EXAMS." ADD INDEX `name` (`name`);"); |
| 370 |
$wpdb->query("ALTER TABLE ".WATU_QUESTIONS." ADD INDEX `exam_id` (`exam_id`);"); |
| 371 |
$wpdb->query("ALTER TABLE ".WATU_QUESTIONS." ADD INDEX `cat_id` (`cat_id`);"); |
| 372 |
$wpdb->query("ALTER TABLE ".WATU_TAKINGS." ADD INDEX `exam_user` (`exam_id`, `user_id`);"); |
| 373 |
} |
| 374 |
|
| 375 |
update_option( "watu_delete_db", '', false ); |
| 376 |
update_option( "watu_version", '2.88', false ); |
| 377 |
|
| 378 |
update_option('watu_admin_notice', __('<h2>Thank you for activating Watu!</h2> <p>Please go to your <a href="admin.php?page=watu_exams">Quizzes page</a> to get started! If this is the first time you have activated the plugin there will be a small demo quiz automatically created for you. Feel free to explore it to get better idea how things work.</p>', 'watu')); |
| 379 |
} |
| 380 |
|
| 381 |
function watu_admin_notice() { |
| 382 |
$notice = get_option('watu_admin_notice'); |
| 383 |
if(!empty($notice)) { |
| 384 |
echo "<div class='updated'>".stripslashes($notice)."</div>"; |
| 385 |
} |
| 386 |
// once shown, cleanup |
| 387 |
update_option('watu_admin_notice', '', false); |
| 388 |
} |
| 389 |
|
| 390 |
function watu_vc_scripts() { |
| 391 |
wp_enqueue_script('jquery'); |
| 392 |
if(is_admin()) wp_enqueue_script('jquery-ui-sortable'); |
| 393 |
|
| 394 |
wp_enqueue_style( |
| 395 |
'watu-style', |
| 396 |
WATU_URL.'style.css', |
| 397 |
array(), |
| 398 |
'2.3.8' |
| 399 |
); |
| 400 |
|
| 401 |
wp_enqueue_script( |
| 402 |
'watu-script', |
| 403 |
WATU_URL.'script.js', |
| 404 |
array(), |
| 405 |
'2.4.4' |
| 406 |
); |
| 407 |
|
| 408 |
$translation_array = array( |
| 409 |
'missed_required_question' => __('You have missed to answer a required question', 'watu'), |
| 410 |
'nothing_selected' => __('You did not select any answer. Are you sure you want to continue?', 'watu'), |
| 411 |
'show_answer' => __('Show Answer', 'watu'), |
| 412 |
'complete_text_captcha' => __('You need to answer the verification question', 'watu'), |
| 413 |
'try_again' => __('Try again', 'watu'), |
| 414 |
'email_required' => __('Valid email address is required.', 'watu'), |
| 415 |
'next_q' => __("Next >", 'watu'), |
| 416 |
'please_wait' => __('Please wait...', 'watu'), |
| 417 |
'ajax_url' => admin_url('admin-ajax.php'), |
| 418 |
'watu_nonce' => wp_create_nonce('watu_reorder_questions'), |
| 419 |
'watu_submit_nonce' => wp_create_nonce('watu_submit_nonce'), |
| 420 |
); |
| 421 |
wp_localize_script( 'watu-script', 'watu_i18n', $translation_array ); |
| 422 |
|
| 423 |
$appid = get_option('watuproshare_facebook_appid'); |
| 424 |
} |
| 425 |
|
| 426 |
function watu_vc_jquery() { |
| 427 |
wp_enqueue_script('jquery'); |
| 428 |
} |
| 429 |
|
| 430 |
// function to conditionally add DB fields |
| 431 |
function watu_add_db_fields($fields, $table) { |
| 432 |
global $wpdb; |
| 433 |
|
| 434 |
// check fields |
| 435 |
$table_fields = $wpdb->get_results("SHOW COLUMNS FROM `$table`"); |
| 436 |
$table_field_names = array(); |
| 437 |
foreach($table_fields as $f) $table_field_names[] = $f->Field; |
| 438 |
$fields_to_add=array(); |
| 439 |
|
| 440 |
foreach($fields as $field) { |
| 441 |
if(!in_array($field['name'], $table_field_names)) { |
| 442 |
$fields_to_add[] = $field; |
| 443 |
} |
| 444 |
} |
| 445 |
|
| 446 |
// now if there are fields to add, run the query |
| 447 |
if(!empty($fields_to_add)) { |
| 448 |
$sql = "ALTER TABLE `$table` "; |
| 449 |
|
| 450 |
foreach($fields_to_add as $cnt => $field) { |
| 451 |
if($cnt > 0) $sql .= ", "; |
| 452 |
$sql .= "ADD $field[name] $field[type]"; |
| 453 |
} |
| 454 |
|
| 455 |
$wpdb->query($sql); |
| 456 |
} |
| 457 |
} |
| 458 |
|
| 459 |
function watu_help() { |
| 460 |
include(WATU_PATH. "/views/help.html.php"); |
| 461 |
} |
| 462 |
|
| 463 |
add_action('init', 'watu_init'); |
| 464 |
add_action('wp_ajax_watu_submit', 'watu_submit'); |
| 465 |
add_action('wp_ajax_nopriv_watu_submit', 'watu_submit'); |
| 466 |
add_action('wp_ajax_watu_taking_details', 'watu_taking_details'); |
| 467 |
add_action('wp_ajax_watu_rated', 'watu_already_rated'); |
| 468 |
add_action('wp_ajax_watu_reorder_questions', 'watu_reorder_questions'); |
| 469 |
|
| 470 |
// hook personal data eraser |
| 471 |
add_filter('wp_privacy_personal_data_erasers', 'watu_register_eraser', 10); |
| 472 |
|