diff --git a/admin/comments.php b/admin/comments.php index 2cd6b313b..cb2f4a7d2 100644 --- a/admin/comments.php +++ b/admin/comments.php @@ -108,6 +108,7 @@ $tabsheet->assign(); $nb_total = 0; $nb_pending = 0; +$nb_validated = 0; $query = ' SELECT @@ -127,6 +128,8 @@ while ($row = pwg_db_fetch_assoc($result)) } } +$nb_validated = $nb_total - $nb_pending; + if (!isset($_GET['filter']) and $nb_pending > 0) { $page['filter'] = 'pending'; @@ -136,16 +139,50 @@ else $page['filter'] = 'all'; } -if (isset($_GET['filter']) and 'pending' == $_GET['filter']) +if (isset($_GET['filter']) and ('pending' == $_GET['filter'] or 'validated' == $_GET['filter'])) { $page['filter'] = $_GET['filter']; } +if (isset($_GET['status'])) +{ + $displayed_status = $_GET['status']; +} +else +{ + $displayed_status = 'all'; +} + +if (isset($_GET['author'])) +{ + $author = $_GET['author']; +} +else +{ + $author = 'all'; +} + +// by default, no filter by date is active +$start = $end = ""; + +if (isset($_GET['start_date'])){ + $start = $_GET['start_date']; +} + +if (isset($_GET['end_date'])){ + $end = $_GET['end_date']; +} + $template->assign( array( 'nb_total' => $nb_total, 'nb_pending' => $nb_pending, + 'nb_validated' => $nb_validated, 'filter' => $page['filter'], + 'displayed_status' => $displayed_status, + 'displayed_author' => $author, + 'START' => $start, + 'END' => $end, ) ); @@ -155,6 +192,10 @@ if ('pending' == $page['filter']) { $where_clauses[] = 'validated=\'false\''; } +if ('validated' == $page['filter']) +{ + $where_clauses[] = 'validated=\'true\''; +} $query = ' SELECT @@ -163,6 +204,7 @@ SELECT c.date, c.author, '.$conf['user_fields']['username'].' AS username, + ui.status, c.content, i.path, i.representative_ext, @@ -173,6 +215,8 @@ SELECT ON i.id = c.image_id LEFT JOIN '.USERS_TABLE.' AS u ON u.'.$conf['user_fields']['id'].' = c.author_id + LEFT JOIN '.USER_INFOS_TABLE.' AS ui + ON ui.user_id = c.author_id WHERE '.implode(' AND ', $where_clauses).' ORDER BY c.date DESC LIMIT '.$page['start'].', '.$conf['comments_page_nb_comments'].' @@ -202,10 +246,12 @@ while ($row = pwg_db_fetch_assoc($result)) 'ID' => $row['id'], 'TN_SRC' => $thumb, 'AUTHOR' => trigger_change('render_comment_author', $author_name), + 'AUTHOR_STATUS' => $row['status'], 'DATE' => format_date($row['date'], array('day_name','day','month','year','time')), 'CONTENT' => trigger_change('render_comment_content',$row['content']), 'IS_PENDING' => ('false' == $row['validated']), 'IP' => $row['anonymous_id'], + 'NUMERICAL_DATE' => $row['date'], ) ); diff --git a/admin/themes/default/template/comments.tpl b/admin/themes/default/template/comments.tpl index 9fda8f142..8ff26389b 100644 --- a/admin/themes/default/template/comments.tpl +++ b/admin/themes/default/template/comments.tpl @@ -1,9 +1,12 @@ +{combine_script id='jquery.ui.slider' require='jquery.ui' load='header' path='themes/default/js/ui/minified/jquery.ui.slider.min.js'} +{combine_css path="themes/default/js/ui/theme/jquery.ui.slider.css"} + {footer_script} jQuery(document).ready(function(){ $("h1").append(""+{$nb_total}+""); function highlighComments() { - jQuery(".checkComment").each(function() { + jQuery(".comment").each(function() { var parent = jQuery(this).parent('tr'); if (jQuery(this).children("input[type=checkbox]").is(':checked')) { jQuery(parent).addClass('selectedComment'); @@ -14,6 +17,103 @@ jQuery(document).ready(function(){ }); } + if ("{$filter}" == "pending"){ + $("#seeWaiting").prop('checked', true); + } + if ("{$filter}" == "validated"){ + $("#seeValidated").prop('checked', true); + } + + $("#seeAll").on("change", function(){ + if ($("#seeAll").prop('checked') == true){ + window.location.replace("{$F_ACTION}&filter=all&status={$displayed_status}&author={$displayed_author}&start_date={$START}&end_date={$END}"); + } + }); + + $("#seeWaiting").on("change", function(){ + if ($("#seeWaiting").prop('checked') == true){ + window.location.replace("{$F_ACTION}&filter=pending&status={$displayed_status}&author={$displayed_author}&start_date={$START}&end_date={$END}"); + } + }); + + $("#seeValidated").on("change", function(){ + if ($("#seeValidated").prop('checked') == true){ + window.location.replace("{$F_ACTION}&filter=validated&status={$displayed_status}&author={$displayed_author}&start_date={$START}&end_date={$END}"); + } + }); + + $("#status_filter").on("change", function(){ + let location = "{$F_ACTION}&filter={$filter}&status=" + $("#status_filter").find(":selected").val().toString() + "&author={$displayed_author}&start_date={$START}&end_date={$END}"; + window.location.replace(location); + }); + + $("#status_filter").val("{$displayed_status}"); + + $("#author_filter").on("change", function(){ + let location = "{$F_ACTION}&filter={$filter}&status={$displayed_status}&author=" + $("#author_filter").find(":selected").val().toString() + "&start_date={$START}&end_date={$END}"; + window.location.replace(location); + }); + + $("#author_filter").val("{$displayed_author}"); + + $("#start_unset").on("click", function(){ + $("#start_date").val(""); + let location = "{$F_ACTION}&filter={$filter}&status={$displayed_status}&author={$displayed_author}&start_date=&end_date={$END}"; + window.location.replace(location); + }); + + $("#start_date").on("focus", function(){ + $(this).data('previous', $(this).val()); + }); + + $("#start_date").val("{$START}".replaceAll("_", "-")); + + $("#start_date").on("change", function(){ + if ($("#end_date").val() != "") + { + var previous = $(this).data('previous'); + var current = new Date($(this).val()); + var max = new Date($("#end_date").val()); + if (current > max){ + $(this).val(previous); + $(this).data('previous', $(this).val()); + return + } + } + $(this).data('previous', $(this).val()); + let location = "{$F_ACTION}&filter={$filter}&status={$displayed_status}&author={$displayed_author}&start_date=" + $(this).val().replaceAll("-", "_") + "&end_date={$END}"; + window.location.replace(location); + }); + + $("#end_unset").on("click", function(){ + $("#end_date").val(""); + let location = "{$F_ACTION}&filter={$filter}&status={$displayed_status}&author={$displayed_author}&start_date={$START}&end_date="; + window.location.replace(location); + }); + + $("#end_date").on("focus", function(){ + $(this).data('previous', $(this).val()); + }); + + $("#end_date").val("{$END}".replaceAll("_", "-")); + + $("#end_date").on("change", function(){ + if ($("#start_date").val() != "") + { + var previous = $(this).data('previous'); + var current = new Date($(this).val()); + var min = new Date($("#start_date").val()); + if (current < min){ + $(this).val(previous); + $(this).data('previous', $(this).val()); + return + } + } + $(this).data('previous', $(this).val()); + let location = "{$F_ACTION}&filter={$filter}&status={$displayed_status}&author={$displayed_author}&start_date={$START}&end_date=" + $(this).val().replaceAll("-", "_"); + window.location.replace(location); + }); + jQuery(".checkComment").click(function(event) { var checkbox = jQuery(this).children("input[type=checkbox]"); if (event.target.type !== 'checkbox') { @@ -23,62 +123,271 @@ jQuery(document).ready(function(){ }); jQuery("#commentSelectAll").click(function () { - jQuery(".checkComment input[type=checkbox]").prop('checked', true); + $(".comment-select-checkbox").prop('checked', true); + $(".comment-select-checkbox").trigger("change"); highlighComments(); return false; }); jQuery("#commentSelectNone").click(function () { - jQuery(".checkComment input[type=checkbox]").prop('checked', false); + $(".comment-select-checkbox").prop('checked', false); + $(".comment-select-checkbox").trigger("change"); highlighComments(); return false; }); jQuery("#commentSelectInvert").click(function () { - jQuery(".checkComment input[type=checkbox]").each(function() { + $(".comment-select-checkbox").each(function() { jQuery(this).prop('checked', !$(this).prop('checked')); }); + $(".comment-select-checkbox").trigger("change"); highlighComments(); return false; }); + $(".comment-select-checkbox").on("change", function(event) { + if ($(this).prop("checked")){ + $(this).removeClass("icon-circle-empty") + $(this).addClass("icon-ok-circled") + } + else { + $(this).removeClass("icon-ok-circled") + $(this).addClass("icon-circle-empty") + } + }); + + $("#toggleSelectionMode").on("click", function() { + if ($(".comment-select-checkbox").css("visibility") == "visible") { + $(".comment-buttons-container").css("visibility", "visible"); + $(".comment-select-checkbox").css("visibility", "hidden"); + $(".comment-selection-content").hide(); + $(".comment-container").css("margin-inline-end", "0em") + $("#advanced-filter-menu").css("margin-inline", "23px 10px") + + $(".comment-select-checkbox").prop('checked', false); + $(".comment-select-checkbox").trigger("change"); + highlighComments(); + } + else { + $(".comment-select-checkbox").css("visibility", "visible"); + $(".comment-buttons-container").css("visibility", "hidden"); + $(".comment-selection-content").css("display", "flex") + $(".comment-container").css("margin-inline-end", "5em") + $("#advanced-filter-menu").css("margin-inline", "23px 270px") + } + }) + + $(".advanced-filter-btn").on("click", function() { + if ($("#advanced-filter-menu").css("display") == "none") { + $("#advanced-filter-menu").css("display", "flex") + $("#advanced-filter-menu").css("margin-bottom", "1em") + $(".commentFilter").css("margin-bottom", "0.2em") + $(".commentFilter .advanced-filter-btn").css("height", "100%") + $(".commentFilter .advanced-filter-btn").css("height", "100%") + } + else { + $("#advanced-filter-menu").css("display", "none") + $("#advanced-filter-menu").css("margin-bottom", "0.2em") + $(".commentFilter").css("margin-bottom", "1em") + $(".commentFilter .advanced-filter-btn").css("height", "20px") + } + }) + + if ("{$displayed_status}" != "all" || "{$displayed_author}" != "all" || "{$START}" != "" || "{$END}" != ""){ + $(".advanced-filter-btn").trigger( "click" ); + } + + $(".delete-comment, #commentDeleteSelected").on("click", function() { + jQuery(this).parent().parent().children("input[type=checkbox]").prop('checked', true); + $("#pendingComments").trigger("submit") + }) + + $(".approve-comment, #commentValidateSelected").on("click", function() { + jQuery(this).parent().parent().children("input[type=checkbox]").prop('checked', true); + $("#pendingComments").trigger("submit") + }) + + $("#commentValidateSelected, #commentDeleteSelected").on("click", function() { + $("#pendingComments").trigger("submit") + }) + }); {/footer_script}