-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanswerinfo.php
64 lines (51 loc) · 1.94 KB
/
answerinfo.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
namespace questionnaire;
function initialize_answerinfo() {
add_ns_action('wp_ajax_qstnr_answer_info', 'ajax_answer_info');
}
function ajax_answer_info() {
if (array_key_exists('postid', $_GET)) {
$postid = $_GET['postid'];
$nonce = $_GET['nonce'];
if (wp_verify_nonce($nonce, QUESTIONNAIRE_NONCE . $postid)) {
$comments = query_comments($postid, array());
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
foreach ( $comments as $comment ) {
wp_delete_comment($comment->comment_ID, true);
}
$ccount = query_comments($postid, array('count' => true));
status_header(SC_OK);
echo json_encode(array('success' => true, 'count' => $ccount));
} else if ($_SERVER['REQUEST_METHOD'] === 'GET') {
status_header(SC_OK);
echo json_encode(array('success' => true, 'answercount' => get_answer_count($postid)));
} else {
status_header(SC_ERROR);
echo ('{"success":false}');
}
die();
}
}
status_header(SC_ERROR);
echo json_encode(array('success' => false));
die();
}
function answerinfo($ldata) {
wp_enqueue_script('qstnr_answerinfo', plugins_url('answerinfo.js', __FILE__));
?>
<div id="qstnr-answerinfo">
<div id="qstnr-answerinfo-errormsg"></div>
<table style="border:none">
<tr>
<td><button id="qstnr-sync-answerinfo"><span class="icon-sync"></span></button><span><?= __('Count of Answers: ', ns_()) ?></span><span class="qstnr-answercount"></span></td>
<td><button type="button" id="qstnr-clearAnswers"><?= __('Delete all answers', ns_()) ?></button></td>
</tr>
</table>
<div class="qstnr-confirm-dialog" style="display:none;">
<div><?= __('Are you sure to delete all answer data?', ns_()); ?></div>
<button type="button" id="qstnr-deleteanswer-confirm-yes"><?= __('OK', ns_());?></button>
<button type="button" id="qstnr-deleteanswer-confirm-no"><?= __('Cancel', ns_());?></button>
</div>
</div>
<?php
}