PluginProbe
Watu Quiz / 3.4.6
Watu Quiz v3.4.6
3.4.8 trunk 3.4.2 3.4.3 3.4.4 3.4.5 3.4.5.1 3.4.5.2 3.4.5.3 3.4.6 3.4.7
watu / controllers / ajax.php

ajax.php in Watu Quiz 3.4.6, at controllers/ajax.php

42 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
4 // ajax calls
5 function watu_submit() {
6 require_once(WATU_PATH."/controllers/show_exam.php");
7 }
8
9 function watu_already_rated() {
10 update_option('watu_rated', 1, false);
11 }
12
13 function watu_reorder_questions() {
14 global $wpdb;
15
16 if(!current_user_can('watu_manage') and !current_user_can('manage_options')) return;
17
18 // Verify nonce for CSRF protection
19 if(!check_admin_referer('watu_reorder_questions', 'watu_nonce')) return;
20
21 // fill all question IDs in array in the same way they come from the sortable Ajax call
22 $qids = [-1];
23 $questions = $_POST['questions'] ?? [];
24 $exam_id = intval($_POST['exam_id']);
25
26 foreach($questions as $question) {
27 $id = intval(str_replace('question-', '', $question));
28 $qids[] = intval($id);
29 }
30 //print_r($qids);
31 // find the min sort order for the group
32 $min_sort_order = $wpdb->get_var($wpdb->prepare("SELECT MIN(sort_order) FROM ".WATU_QUESTIONS."
33 WHERE exam_id=%d AND ID IN (".implode(',', $qids).")", $exam_id));
34
35 // go through the questions and increment the min for each of them
36 foreach($qids as $qid) {
37 if($qid == -1) continue;
38 $wpdb->query($wpdb->prepare("UPDATE ".WATU_QUESTIONS." SET sort_order=%d WHERE ID=%d", $min_sort_order, $qid));
39 $min_sort_order++;
40 }
41 }
42