| 1 |
<?php |
| 2 |
global $wpdb; |
| 3 |
$poll_id = isset($_GET['poll']) ? intval($_GET['poll']) : null; |
| 4 |
if($poll_id === null){ |
| 5 |
wp_redirect( admin_url('admin.php') . '?page=' . $this->plugin_name . '-ays-results' ); |
| 6 |
} |
| 7 |
|
| 8 |
if (isset($_REQUEST['ays_poll_tab_results'])) { |
| 9 |
$ays_poll_tab = sanitize_text_field($_REQUEST['ays_poll_tab_results']); |
| 10 |
} else { |
| 11 |
$ays_poll_tab = 'tab1'; |
| 12 |
} |
| 13 |
?> |
| 14 |
<script> |
| 15 |
(function ($) { |
| 16 |
$('#adminmenu').find('li>a[href$="poll-maker-ays-results"]') |
| 17 |
.addClass('current') |
| 18 |
.parent() |
| 19 |
.addClass('current') |
| 20 |
.parent().parent() |
| 21 |
.removeClass('wp-not-current-submenu').addClass('wp-has-current-submenu').addClass('wp-menu-open') |
| 22 |
.find('a.wp-has-submenu') |
| 23 |
.removeClass('wp-not-current-submenu').addClass('wp-has-current-submenu').addClass('wp-menu-open'); |
| 24 |
})(jQuery) |
| 25 |
</script> |
| 26 |
<div class="wrap ays_polls_each_results_list_table"> |
| 27 |
<div class="ays-poll-heading-box"> |
| 28 |
<div class="ays-poll-wordpress-user-manual-box"> |
| 29 |
<a href="https://ays-pro.com/wordpress-poll-maker-user-manual" target="_blank"><?php echo __("View Documentation", "poll-maker"); ?></a> |
| 30 |
</div> |
| 31 |
</div> |
| 32 |
<h1 class="wp-heading-inline"> |
| 33 |
<div class="ays-poll-each-results-heading-inline"> |
| 34 |
<?php |
| 35 |
global $wpdb; |
| 36 |
$poll_id = isset($_GET['poll']) ? intval($_GET['poll']) : null; |
| 37 |
if($poll_id === null){ |
| 38 |
wp_redirect( admin_url('admin.php') . '?page=' . $this->plugin_name . '-ays-results' ); |
| 39 |
} |
| 40 |
|
| 41 |
$polls_table = $wpdb->prefix . 'ayspoll_polls'; |
| 42 |
$sql = "SELECT * FROM {$polls_table} WHERE id =". $poll_id; |
| 43 |
$poll = $wpdb->get_row( $sql, 'ARRAY_A' ); |
| 44 |
|
| 45 |
$user_id = get_current_user_id(); |
| 46 |
|
| 47 |
echo sprintf('<a href="?page=%s" class="forArrow"><img src="' . POLL_MAKER_AYS_ADMIN_URL . '/images/icons/arrow-left.svg"></a>', esc_attr(rtrim($_REQUEST['page'], '-each'))); |
| 48 |
echo esc_html(stripslashes($_GET['title'])); |
| 49 |
?> |
| 50 |
</div> |
| 51 |
</h1> |
| 52 |
<div class="nav-tab-wrapper"> |
| 53 |
<a href="#statistics" class="ays-poll-google-chart nav-tab <?php echo ($ays_poll_tab == 'tab1') ? 'nav-tab-active' : ''; ?>" data-tab="tab1"><?= __('Statistics', "poll-maker"); ?></a> |
| 54 |
<a href="#poststuff" class="nav-tab <?php echo ($ays_poll_tab == 'tab2') ? 'nav-tab-active' : ''; ?>" data-tab="tab2"><?= __('Results', "poll-maker"); ?></a> |
| 55 |
</div> |
| 56 |
<div id="poststuff" class="ays-poll-tab-content <?php echo ($ays_poll_tab == 'tab2') ? 'ays-poll-tab-content-active' : ''; ?>"> |
| 57 |
<div id="post-body" class="metabox-holder"> |
| 58 |
<div id="post-body-content"> |
| 59 |
<div class="meta-box-sortables ui-sortable"> |
| 60 |
<form method="post"> |
| 61 |
<input type="hidden" name="ays_poll_tab_results" value="<?php echo htmlentities($ays_poll_tab); ?>" id="ays_poll_active_tab_settings"> |
| 62 |
<?php |
| 63 |
$this->each_results_obj->prepare_items(); |
| 64 |
$search = __("Search" , "poll-maker"); |
| 65 |
$this->each_results_obj->search_box($search, $this->plugin_name); |
| 66 |
$this->each_results_obj->display(); |
| 67 |
?> |
| 68 |
</form> |
| 69 |
</div> |
| 70 |
</div> |
| 71 |
</div> |
| 72 |
<br class="clear"> |
| 73 |
</div> |
| 74 |
<div id="statistics" class="ays-poll-tab-content <?php echo ($ays_poll_tab == 'tab1') ? 'ays-poll-tab-content-active' : ''; ?>"> |
| 75 |
<div class="results-apm" id="<?php echo 'pollResultId-' . $poll_id ?>"> |
| 76 |
</div> |
| 77 |
</div> |
| 78 |
<div id="ays-results-modal" class="ays-modal"> |
| 79 |
<div class="ays-modal-content"> |
| 80 |
<div class="ays-poll-preloader"> |
| 81 |
<img class="loader" src="<?php echo POLL_MAKER_AYS_ADMIN_URL; ?>/images/loaders/tail-spin.svg"> |
| 82 |
</div> |
| 83 |
<div class="ays-modal-header"> |
| 84 |
<span class="ays-close" id="ays-close-results">×</span> |
| 85 |
<h2><?php echo __("Details report", "poll-maker"); ?></h2> |
| 86 |
</div> |
| 87 |
<div class="ays-modal-body" id="ays-results-body"> |
| 88 |
<table id="ays-results-table"> |
| 89 |
</table> |
| 90 |
</div> |
| 91 |
</div> |
| 92 |
</div> |
| 93 |
</div> |
| 94 |
|
| 95 |
<script> |
| 96 |
(function ($) { |
| 97 |
String.prototype.stripSlashes = function () { |
| 98 |
return this.replace(/\\(.)/mg, "$1"); |
| 99 |
} |
| 100 |
|
| 101 |
<?php |
| 102 |
$poll_id = absint($_GET['poll']); |
| 103 |
$current_tab = $ays_poll_tab == 'tab1' ? 1 : 2; |
| 104 |
$chart_data = $this->each_results_obj->get_poll_data_chart($poll_id); |
| 105 |
?> |
| 106 |
|
| 107 |
var pageTab = <?= $current_tab ?>; |
| 108 |
|
| 109 |
var pollId = <?php echo ($poll_id) ?>; |
| 110 |
var chart_data = <?= !empty($chart_data) ? json_encode($chart_data) : 0 ?>; |
| 111 |
var resultStatistics = $('#pollResultId-' + pollId); |
| 112 |
|
| 113 |
var votesSum = 0; |
| 114 |
var votesMax = 0; |
| 115 |
var answer; |
| 116 |
for ( answer in chart_data) { |
| 117 |
votesSum = Math.abs(chart_data[answer].votes) + votesSum; |
| 118 |
if (+chart_data[answer].votes > votesMax) { |
| 119 |
votesMax = +chart_data[answer].votes; |
| 120 |
} |
| 121 |
} |
| 122 |
var answer2 = chart_data; |
| 123 |
|
| 124 |
var widths = []; |
| 125 |
for (var i = 0; i < chart_data.length; i++) { |
| 126 |
var answer = answer2[i]; |
| 127 |
widths[i] = {}; |
| 128 |
var width = (answer.votes * 100 / votesSum).toFixed(0); |
| 129 |
widths[i].width = width; |
| 130 |
widths[i].index = i; |
| 131 |
} |
| 132 |
|
| 133 |
var showChartType = chart_data[0]['show_chart_type']; |
| 134 |
var barChartType = (typeof showChartType != "undefined" && showChartType !== null && showChartType.length > 0 && showChartType != "") ? showChartType.replace(/"/g, '') : "default_bar_chart"; |
| 135 |
|
| 136 |
if(barChartType == 'google_bar_chart') { |
| 137 |
var chartHeight = typeof chart_data[0]['show_chart_type_google_height'] != "undefined" && chart_data[0]['show_chart_type_google_height'] !== null && chart_data[0]['show_chart_type_google_height'].length > 0 && chart_data[0]['show_chart_type_google_height'] != '' ? chart_data[0]['show_chart_type_google_height'] : 400; |
| 138 |
var aysBarChartData = new Array(['', '']); |
| 139 |
for (var tox in widths) { |
| 140 |
var chartRealVotes = +answer2[widths[tox].index].votes; |
| 141 |
var answerTextVal = answer2[widths[tox].index].answer; |
| 142 |
answerTextVal = answerTextVal.replace(/\\/g, ''); |
| 143 |
aysBarChartData.push([ |
| 144 |
answerTextVal, |
| 145 |
parseInt(chartRealVotes) |
| 146 |
]); |
| 147 |
} |
| 148 |
|
| 149 |
google.charts.load('current', {packages: ['corechart', 'bar']}); |
| 150 |
google.charts.setOnLoadCallback(drawBasic); |
| 151 |
|
| 152 |
function drawBasic() { |
| 153 |
var data = google.visualization.arrayToDataTable(aysBarChartData); |
| 154 |
|
| 155 |
var groupData = google.visualization.data.group( |
| 156 |
data, |
| 157 |
[{column: 0, modifier: function () {return 'total'}, type:'string'}], |
| 158 |
[{column: 1, aggregation: google.visualization.data.sum, type: 'number'}] |
| 159 |
); |
| 160 |
|
| 161 |
var formatPercent = new google.visualization.NumberFormat({ |
| 162 |
pattern: '#%' |
| 163 |
}); |
| 164 |
|
| 165 |
var formatShort = new google.visualization.NumberFormat({ |
| 166 |
pattern: 'short' |
| 167 |
}); |
| 168 |
|
| 169 |
var view = new google.visualization.DataView(data); |
| 170 |
view.setColumns([0, 1, { |
| 171 |
calc: function (dt, row) { |
| 172 |
if( groupData.getValue(0, 1) == 0 ){ |
| 173 |
return amount; |
| 174 |
} |
| 175 |
var amount = formatShort.formatValue(dt.getValue(row, 1)); |
| 176 |
var percent = formatPercent.formatValue(dt.getValue(row, 1) / groupData.getValue(0, 1)); |
| 177 |
return amount + ' (' + percent + ')'; |
| 178 |
}, |
| 179 |
type: 'string', |
| 180 |
role: 'annotation' |
| 181 |
}]); |
| 182 |
var options = { |
| 183 |
maxWidth: '100%', |
| 184 |
height: chartHeight, |
| 185 |
legend: { position: 'none' }, |
| 186 |
axes: { |
| 187 |
x: { |
| 188 |
0: { side: 'bottom'} |
| 189 |
} |
| 190 |
}, |
| 191 |
bars: 'horizontal', |
| 192 |
bar: { groupWidth: "90%" }, |
| 193 |
}; |
| 194 |
|
| 195 |
var chart = new google.visualization.BarChart(document.getElementById('pollResultId-' + pollId)); |
| 196 |
if (pageTab == 1) { |
| 197 |
chart.draw(view,options); |
| 198 |
resizeChart(chart, data, options); |
| 199 |
} else { |
| 200 |
var statisticsTab = document.querySelector("a[href='#statistics']"); |
| 201 |
statisticsTab.addEventListener('click', function() { |
| 202 |
chart.draw(view,options); |
| 203 |
resizeChart(chart, data, options); |
| 204 |
}) |
| 205 |
} |
| 206 |
} |
| 207 |
|
| 208 |
} else if(barChartType == "default_bar_chart") { |
| 209 |
for (var i = 0; i < chart_data.length; i++) { |
| 210 |
var answer = chart_data; |
| 211 |
|
| 212 |
var starIcons = '<i class="ays_poll_far ays_poll_fa-star"></i>'; |
| 213 |
var emojiIcons = [ |
| 214 |
'<i class="ays_poll_far ays_poll_fa-dizzy"></i>', |
| 215 |
'<i class="ays_poll_far ays_poll_fa-smile"></i>', |
| 216 |
'<i class="ays_poll_far ays_poll_fa-meh"></i>', |
| 217 |
'<i class="ays_poll_far ays_poll_fa-frown"></i>', |
| 218 |
'<i class="ays_poll_far ays_poll_fa-tired"></i>', |
| 219 |
]; |
| 220 |
var handIcons = [ |
| 221 |
'<i class="ays_poll_far ays_poll_fa-thumbs-up"></i>', |
| 222 |
'<i class="ays_poll_far ays_poll_fa-thumbs-down"></i>' |
| 223 |
]; |
| 224 |
|
| 225 |
// var percentColor = chart_data[0]['main_color'].replace(/"/g, ''); |
| 226 |
// var resultColorsRgba = chart_data[0]['result_in_rgba']; |
| 227 |
var pollType = chart_data[0]['type'].replace(/"/g, ''); |
| 228 |
var pollViewType = chart_data[0]['view_type'].replace(/"/g, ''); |
| 229 |
var enableImageShowing = (chart_data[0]['show_answer_images'] != null) ?chart_data[0]['show_answer_images'].replace(/"/g, '') : ''; |
| 230 |
|
| 231 |
var answerDiv = $('<div class="answer-title flex-apm"></div>') |
| 232 |
var answerBar = $('<div class="answer-percent" data-percent="'+widths[i].width+'"></div>'); |
| 233 |
|
| 234 |
// if (resultColorsRgba) { |
| 235 |
// answerBar.attr('style', 'background-color:'+hexToRgba(percentColor)+' !important; border: 1px solid ' + percentColor +' !important;'); |
| 236 |
// } |
| 237 |
// else{ |
| 238 |
// answerBar.attr('style', 'background-color:'+percentColor); |
| 239 |
// } |
| 240 |
|
| 241 |
answerBar.css({ |
| 242 |
width: '1%' |
| 243 |
}); |
| 244 |
|
| 245 |
var answerText = ''; |
| 246 |
var pollShowAnswerImage = false; |
| 247 |
switch (pollType) { |
| 248 |
case 'choosing': |
| 249 |
pollShowAnswerImage = (enableImageShowing == "on") ? true : false; |
| 250 |
if(pollShowAnswerImage){ |
| 251 |
var answerImage = typeof answer[widths[i].index].answer_img != "undefined" || typeof (answer[widths[i].index].answer_img) != "" ? answer[widths[i].index].answer_img : ""; |
| 252 |
var answerImageBox = $("<div class='ays-poll-answers-image-box-empty-image'></div>"); |
| 253 |
var answerImageIsEmptyClass = "ays-poll-answers-box-no-image"; |
| 254 |
if(answerImage != ""){ |
| 255 |
answerImageIsEmptyClass = "ays-poll-answers-box"; |
| 256 |
answerImageBox = $("<div class='ays-poll-answers-image-box'><img src="+answerImage+" class='ays-poll-answers-current-image'></div>"); |
| 257 |
} |
| 258 |
var answerTextAndPercent = $("<div class='ays-poll-answer-text-and-percent-box'></div>"); |
| 259 |
var answerMainDiv = $('<div class='+answerImageIsEmptyClass+'></div>'); |
| 260 |
} |
| 261 |
|
| 262 |
answerText = $('<span class="answer-text"></span>'); |
| 263 |
var htmlstr = htmlstr = answer[widths[i].index].answer.stripSlashes(); |
| 264 |
|
| 265 |
answerText.html(htmlstr); |
| 266 |
break; |
| 267 |
case 'rating': |
| 268 |
switch (pollViewType) { |
| 269 |
case 'emoji': |
| 270 |
answerText = emojiIcons[chart_data.length / 2 + 1.5 - widths[i].index]; |
| 271 |
break; |
| 272 |
|
| 273 |
case 'star': |
| 274 |
for (var j = 0; j <= widths[i].index; j++) { |
| 275 |
answerText += starIcons; |
| 276 |
} |
| 277 |
break; |
| 278 |
} |
| 279 |
answerText = $('<span class="answer-text">'+answerText+'</span>'); |
| 280 |
break; |
| 281 |
case 'voting': |
| 282 |
switch (pollViewType) { |
| 283 |
case 'hand': |
| 284 |
answerText = handIcons[widths[i].index]; |
| 285 |
break; |
| 286 |
|
| 287 |
case 'emoji': |
| 288 |
answerText = emojiIcons[2 * widths[i].index + 1]; |
| 289 |
break; |
| 290 |
} |
| 291 |
answerText = $('<span class="answer-text">'+answerText+'</span>'); |
| 292 |
break; |
| 293 |
} |
| 294 |
|
| 295 |
var answerVotes = $('<span class="answer-votes"></span>'); |
| 296 |
answerVotes.text(answer[widths[i].index].votes); |
| 297 |
|
| 298 |
if(!pollShowAnswerImage){ |
| 299 |
answerDiv.append(answerText).append(answerVotes).appendTo(resultStatistics); |
| 300 |
$(resultStatistics).append(answerBar); |
| 301 |
} |
| 302 |
else{ |
| 303 |
answerMainDiv.appendTo(resultStatistics); |
| 304 |
answerTextAndPercent.appendTo(answerMainDiv); |
| 305 |
answerDiv.append(answerText).append(answerVotes).appendTo(answerTextAndPercent); |
| 306 |
} |
| 307 |
answerBar.appendTo(answerTextAndPercent); |
| 308 |
} |
| 309 |
resultStatistics.find('.answer-percent').each(function () { |
| 310 |
var percent = $(this).attr('data-percent'); |
| 311 |
$(this).css({ |
| 312 |
width: (percent || 1) + '%' |
| 313 |
}); |
| 314 |
var aaa = $(this); |
| 315 |
aaa.text(percent > 5 ? percent + '%' : ''); |
| 316 |
}); |
| 317 |
|
| 318 |
resultStatistics.parents('.ays_poll_category-container').find('.ays-poll-next-btn').prop('disabled', false); |
| 319 |
var vvv = resultStatistics.parents('.ays_poll_category-container').data("var"); |
| 320 |
window['showNext'+vvv] = true; |
| 321 |
|
| 322 |
if (typeof(window['catIndex'+vvv]) !== 'undefined') { |
| 323 |
if (typeof(window['pollsGlobalPool'+vvv]) !== 'undefined') { |
| 324 |
if (window['catIndex'+vvv] == window['pollsGlobalPool'+vvv].length-1) { |
| 325 |
resultStatistics.parents('.ays_poll_category-container').find('.ays-poll-next-btn').prop('disabled', true); |
| 326 |
} |
| 327 |
} |
| 328 |
if (window['catIndex'+vvv] == 0 && resultStatistics.parents('.ays_poll_category-container').find('.results-apm').length > 0) { |
| 329 |
resultStatistics.parents('.ays_poll_category-container').find('.ays-poll-previous-btn').prop('disabled', true); |
| 330 |
} |
| 331 |
} |
| 332 |
} |
| 333 |
|
| 334 |
function hexToRgba(hex, alfa) { |
| 335 |
var c; |
| 336 |
if (alfa == null) { |
| 337 |
alfa = 1; |
| 338 |
} |
| 339 |
if (/^#([A-Fa-f0-9]{3}){1,2}$/.test(hex)) { |
| 340 |
c= hex.substring(1).split(''); |
| 341 |
if(c.length== 3){ |
| 342 |
c= [c[0], c[0], c[1], c[1], c[2], c[2]]; |
| 343 |
} |
| 344 |
c= '0x'+c.join(''); |
| 345 |
return 'rgba('+[(c>>16)&255, (c>>8)&255, c&255].join(',')+','+alfa+')'; |
| 346 |
} |
| 347 |
} |
| 348 |
|
| 349 |
})(jQuery); |
| 350 |
</script> |