1<?php 2 3/** 4 * Shows all comments in the categories and provides a link to delete comments. 5 * 6 * This Source Code Form is subject to the terms of the Mozilla Public License, 7 * v. 2.0. If a copy of the MPL was not distributed with this file, You can 8 * obtain one at http://mozilla.org/MPL/2.0/. 9 * 10 * @package phpMyFAQ 11 * @author Thorsten Rinne <thorsten@phpmyfaq.de> 12 * @copyright 2007-2020 phpMyFAQ Team 13 * @license http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0 14 * @link https://www.phpmyfaq.de 15 * @since 2007-03-04 16 */ 17 18use phpMyFAQ\Category; 19use phpMyFAQ\Comments; 20use phpMyFAQ\Date; 21use phpMyFAQ\Entity\CommentType; 22use phpMyFAQ\Faq; 23 24if (!defined('IS_VALID_PHPMYFAQ')) { 25 http_response_code(400); 26 exit(); 27} 28 29?> 30 <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom"> 31 <h1 class="h2"> 32 <i aria-hidden="true" class="fa fa-comments-o"></i> 33 <?= $PMF_LANG['ad_comment_administration'] ?> 34 </h1> 35 </div> 36<?php 37 38echo '<div id="returnMessage"></div>'; 39 40if ($user->perm->checkRight($user->getUserId(), 'delcomment')) { 41 $comment = new Comments($faqConfig); 42 $category = new Category($faqConfig, [], false); 43 $category->setUser($currentAdminUser); 44 $category->setGroups($currentAdminGroups); 45 $faq = new Faq($faqConfig); 46 $date = new Date($faqConfig); 47 48 $category->buildTree(); 49 $faqComments = $comment->getAllComments(CommentType::FAQ); 50 51 printf("<header><h3>%s</h3></header>\n", $PMF_LANG['ad_comment_faqs']); 52 if (count($faqComments)) { 53 ?> 54 <form id="faqCommentSelection" name="faqCommentSelection" method="post" accept-charset="utf-8"> 55 <input type="hidden" name="ajax" value="comment"/> 56 <input type="hidden" name="ajaxaction" value="delete"/> 57 <table class="table table-striped"> 58 <?php 59 $lastCommentId = 0; 60 foreach ($faqComments as $faqComment) { 61 if ($faqComment->getId() == $lastCommentId) { 62 continue; 63 } 64 ?> 65 <tr id="comments_<?= $faqComment->getId() ?>"> 66 <td> 67 <label> 68 <input id="faq_comments[<?= $faqComment->getId() ?>]" 69 name="faq_comments[<?= $faqComment->getId() ?>]" 70 value="<?= $faqComment->getRecordId() ?>" type="checkbox"> 71 </label> 72 </td> 73 <td> 74 <span style="font-weight: bold;"> 75 <a href="mailto:<?= $faqComment->getEmail() ?>"> 76 <?= $faqComment->getUsername() ?> 77 </a> | 78 <?= $date->format(date('Y-m-d H:i', $faqComment->getDate())) ?> | 79 <a href="<?php printf('../?action=faq&cat=%d&id=%d&artlang=%s', 80 $faqComment->getCategoryId(), 81 $faqComment->getRecordId(), 82 $faqLangCode) ?>"> 83 <?= $faq->getRecordTitle($faqComment->getRecordId()) ?> 84 </a> 85 </span><br/> 86 <?= $faqComment->getComment() ?> 87 </td> 88 </tr> 89 <?php 90 $lastCommentId = $faqComment->getId(); 91 } 92 ?> 93 </table> 94 <div class="text-right"> 95 <button class="btn btn-danger" id="submitFaqComments" type="submit" name="submit"> 96 <?= $PMF_LANG['ad_entry_delete'] ?> 97 </button> 98 </div> 99 </form> 100 <?php 101 102 } else { 103 echo '<p><strong>n/a</strong></p>'; 104 } 105 106 $newsComments = $comment->getAllComments(CommentType::NEWS); 107 108 printf("<header><h3>%s</h3></header>\n", $PMF_LANG['ad_comment_news']); 109 if (count($newsComments)) { 110 ?> 111 <form id="newsCommentSelection" name="newsCommentSelection" method="post" accept-charset="utf-8"> 112 <input type="hidden" name="ajax" value="comment"/> 113 <input type="hidden" name="ajaxaction" value="delete"/> 114 <table class="table table-striped"> 115 <?php 116 foreach ($newsComments as $newsComment) { ?> 117 <tr id="comments_<?= $newsComment->getId() ?>"> 118 <td> 119 <label> 120 <input id="news_comments[<?= $newsComment->getId() ?>]" 121 name="news_comments[<?= $newsComment->getId() ?>]" 122 value="<?= $newsComment->getRecordId() ?>" type="checkbox"> 123 </label> 124 </td> 125 <td> 126 <span style="font-weight: bold;"> 127 <a href="mailto:<?= $newsComment->getEmail() ?>"> 128 <?= $newsComment->getUsername() ?> 129 </a> | 130 <?= $date->format(date('Y-m-d H:i', $faqComment->getDate())) ?> | 131 <a href="<?php printf('../?action=news&id=%d&artlang=%s', $faqComment->getRecordId(), $faqLangCode) ?>"> 132 <i class="fa fa-newspaper-o" aria-hidden="true"></i> 133 </a> 134 </span><br/> 135 <?= $newsComment->getComment() ?> 136 </td> 137 </tr> 138 <?php 139 140 } 141 ?> 142 </table> 143 <div class="text-right"> 144 <button class="btn btn-danger" id="submitNewsComments" type="submit" name="submit"> 145 <?= $PMF_LANG['ad_entry_delete'] ?> 146 </button> 147 </div> 148 </form> 149 <?php 150 151 } else { 152 echo '<p><strong>n/a</strong></p>'; 153 } 154 ?> 155 156 <script> 157 (() => { 158 $('#submitFaqComments').on('click', () => { 159 deleteComments('faq'); 160 return false; 161 }); 162 $('#submitNewsComments').on('click', () => { 163 deleteComments('news'); 164 return false; 165 }); 166 })(); 167 168 function deleteComments(type) { 169 const savingIndicator = $('#pmf-admin-saving-data-indicator'), 170 returnMessage = $('#returnMessage'), 171 comments = $('#' + type + 'CommentSelection').serialize(); 172 173 returnMessage.empty(); 174 $.ajax({ 175 type: 'POST', 176 url: 'index.php?action=ajax&ajax=comment', 177 data: comments, 178 success: function (msg) { 179 if (msg === 1) { 180 savingIndicator.html('<i class="fa fa-cog fa-spin fa-fw"></i><span class="sr-only">Deleting ...</span>'); 181 $('tr td input:checked').parent().parent().parent().fadeOut('slow'); 182 savingIndicator.fadeOut('slow'); 183 returnMessage.html('<p class="alert alert-success"><?= $PMF_LANG['ad_entry_commentdelsuc'] ?></p>'); 184 } else { 185 returnMessage.html('<p class="alert alert-danger"><?= $PMF_LANG['ad_entry_commentdelfail'] ?></p>'); 186 } 187 } 188 }); 189 return false; 190 } 191 192 </script> 193 <?php 194} else { 195 echo $PMF_LANG['err_NotAuth']; 196} 197