diff --git a/phpmyfaq/admin/index.php b/phpmyfaq/admin/index.php index 8616192253..02cce99963 100755 --- a/phpmyfaq/admin/index.php +++ b/phpmyfaq/admin/index.php @@ -275,7 +275,7 @@ require 'record.delatt.php'; break; case 'question': - require 'record.questions.php'; + require 'open-questions.php'; break; case 'comments': require 'record.comments.php'; diff --git a/phpmyfaq/admin/open-questions.php b/phpmyfaq/admin/open-questions.php new file mode 100644 index 0000000000..aaab3456ad --- /dev/null +++ b/phpmyfaq/admin/open-questions.php @@ -0,0 +1,90 @@ + + * @copyright 2003-2024 phpMyFAQ Team + * @license https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0 + * @link https://www.phpmyfaq.de + * @since 2003-02-24 + */ + +use phpMyFAQ\Category; +use phpMyFAQ\Configuration; +use phpMyFAQ\Date; +use phpMyFAQ\Enums\PermissionType; +use phpMyFAQ\Filter; +use phpMyFAQ\Question; +use phpMyFAQ\Session\Token; +use phpMyFAQ\Template\CategoryNameTwigExtension; +use phpMyFAQ\Template\TwigWrapper; +use phpMyFAQ\Translation; +use phpMyFAQ\User\CurrentUser; +use Twig\Extension\DebugExtension; +use Twig\Extra\Intl\IntlExtension; + +if (!defined('IS_VALID_PHPMYFAQ')) { + http_response_code(400); + exit(); +} + +$faqConfig = Configuration::getConfigurationInstance(); +$user = CurrentUser::getCurrentUser($faqConfig); + +if ($user->perm->hasPermission($user->getUserId(), PermissionType::QUESTION_DELETE->value)) { + $category = new Category($faqConfig, [], false); + $question = new Question($faqConfig); + $category->setUser($currentAdminUser); + $category->setGroups($currentAdminGroups); + $date = new Date($faqConfig); + + $questionId = Filter::filterInput(INPUT_GET, 'id', FILTER_VALIDATE_INT); + $csrfToken = Filter::filterInput(INPUT_GET, 'csrf', FILTER_SANITIZE_SPECIAL_CHARS); + + if ($csrfToken && Token::getInstance()->verifyToken('toggle-question-visibility', $csrfToken)) { + $csrfChecked = true; + } else { + $csrfChecked = false; + } + + $toggle = Filter::filterInput(INPUT_GET, 'is_visible', FILTER_SANITIZE_SPECIAL_CHARS); + if ($csrfChecked && $toggle === 'toggle') { + $isVisible = $question->getVisibility($questionId); + $question->setVisibility($questionId, ($isVisible == 'N' ? 'Y' : 'N')); + } + + $twig = new TwigWrapper(PMF_ROOT_DIR . '/assets/templates'); + $twig->addExtension(new IntlExtension()); + $twig->addExtension(new DebugExtension()); + $twig->addExtension(new CategoryNameTwigExtension()); + $template = $twig->loadTemplate('./admin/content/open-questions.twig'); + + $openQuestions = $question->getAll(); + + $templateVars = [ + 'msgOpenQuestions' => Translation::get('msgOpenQuestions'), + 'csrfTokenDeleteQuestion' => Token::getInstance()->getTokenString('delete-questions'), + 'currentLocale' => $faqConfig->getLanguage()->getLanguage(), + 'msgAuthor' => Translation::get('ad_entry_author'), + 'msgQuestion' => Translation::get('ad_entry_theme'), + 'msgVisibility' => Translation::get('ad_entry_visibility'), + 'questions' => $openQuestions, + 'yes' => Translation::get('ad_gen_yes'), + 'no' => Translation::get('ad_gen_no'), + 'enableCloseQuestion' => $faqConfig->get('records.enableCloseQuestion'), + 'msg2answerFAQ' => Translation::get('msg2answerFAQ'), + 'msgTakeQuestion' => Translation::get('ad_ques_take'), + 'csrfTokenToggleVisibility' => Token::getInstance()->getTokenString('toggle-question-visibility'), + 'msgDeleteAllOpenQuestions' => Translation::get('ad_entry_delete'), + ]; + + echo $template->render($templateVars); +} else { + require __DIR__ . '/no-permission.php'; +} diff --git a/phpmyfaq/admin/record.questions.php b/phpmyfaq/admin/record.questions.php deleted file mode 100644 index 229faf53ab..0000000000 --- a/phpmyfaq/admin/record.questions.php +++ /dev/null @@ -1,144 +0,0 @@ - - * @copyright 2003-2024 phpMyFAQ Team - * @license https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0 - * @link https://www.phpmyfaq.de - * @since 2003-02-24 - */ - -use phpMyFAQ\Category; -use phpMyFAQ\Date; -use phpMyFAQ\Enums\PermissionType; -use phpMyFAQ\Filter; -use phpMyFAQ\Question; -use phpMyFAQ\Session\Token; -use phpMyFAQ\Strings; -use phpMyFAQ\Translation; - -if (!defined('IS_VALID_PHPMYFAQ')) { - http_response_code(400); - exit(); -} -?> -
-

- - -

-
- -
-
- perm->hasPermission($user->getUserId(), PermissionType::QUESTION_DELETE->value)) { - $category = new Category($faqConfig, [], false); - $question = new Question($faqConfig); - $category->setUser($currentAdminUser); - $category->setGroups($currentAdminGroups); - $date = new Date($faqConfig); - $questionId = Filter::filterInput(INPUT_GET, 'id', FILTER_VALIDATE_INT); - $csrfToken = Filter::filterInput(INPUT_GET, 'csrf', FILTER_SANITIZE_SPECIAL_CHARS); - - if ($csrfToken && Token::getInstance()->verifyToken('toggle-question-visibility', $csrfToken)) { - $csrfChecked = true; - } else { - $csrfChecked = false; - } - - $toggle = Filter::filterInput(INPUT_GET, 'is_visible', FILTER_SANITIZE_SPECIAL_CHARS); - if ($csrfChecked && $toggle === 'toggle') { - $isVisible = $question->getVisibility($questionId); - $question->setVisibility($questionId, ($isVisible == 'N' ? 'Y' : 'N')); - } - - echo '
'; - - $openQuestions = $question->getAll(); - - if ((is_countable($openQuestions) ? count($openQuestions) : 0) > 0) { - ?> -
- getTokenInput('delete-questions') ?> - - - - - - - - - - - - - - - - - - - - -
?
- - - format(Date::createIsoDate($openQuestion->getCreated())) ?> -
- - getUsername()) ?> - -
- - categoryName[$openQuestion->getCategoryId()]['name'] ?? '') ?> - -
- getQuestion()) ?> -
- - isVisible()) ? Translation::get('ad_gen_yes') : Translation::get('ad_gen_no') ?> - - - get('records.enableCloseQuestion') && $openQuestion->getAnswerId()) { ?> - - - - - - - - -
- -
- -
- -
- -
-
diff --git a/phpmyfaq/admin/statistics.admin-log.php b/phpmyfaq/admin/statistics.admin-log.php index 31fa73535d..5f3db56d0b 100644 --- a/phpmyfaq/admin/statistics.admin-log.php +++ b/phpmyfaq/admin/statistics.admin-log.php @@ -22,7 +22,6 @@ use phpMyFAQ\Filter; use phpMyFAQ\Pagination; use phpMyFAQ\Session\Token; -use phpMyFAQ\Strings; use phpMyFAQ\Template\TwigWrapper; use phpMyFAQ\Template\UserNameTwigExtension; use phpMyFAQ\Translation; diff --git a/phpmyfaq/assets/templates/admin/content/open-questions.twig b/phpmyfaq/assets/templates/admin/content/open-questions.twig index e69de29bb2..94787a458b 100644 --- a/phpmyfaq/assets/templates/admin/content/open-questions.twig +++ b/phpmyfaq/assets/templates/admin/content/open-questions.twig @@ -0,0 +1,78 @@ +
+

+ + {{ msgOpenQuestions }} +

+
+ +
+
+ +
+ +
+ + + + + + + + + + + + + {% for question in questions %} + + + + + + + + {% endfor %} + +
{{ msgAuthor }}{{ msgQuestion }}{{ msgVisibility }}?
+ + + {{ question.created | format_datetime(locale=currentLocale) }} +
+ + {{ question.username }} + +
+ + {{ question.categoryId | categoryName }} + +
+ {{ question.question }} +
+ + {{ question.isVisible == 'Y' ? yes : no }} + + + {% if enableCloseQuestion and question.answerId %} + + {{ msg2answerFAQ }} + + {% else %} + + {{ msgTakeQuestion }} + + {% endif %} +
+ +
+ +
+ +
+
+
diff --git a/phpmyfaq/src/phpMyFAQ/Question.php b/phpmyfaq/src/phpMyFAQ/Question.php index 8af78cd13c..1200b005bf 100644 --- a/phpmyfaq/src/phpMyFAQ/Question.php +++ b/phpmyfaq/src/phpMyFAQ/Question.php @@ -156,7 +156,7 @@ public function getAll(bool $showAll = true): array ->setEmail($row->email) ->setCategoryId($row->category_id) ->setQuestion($row->question) - ->setCreated($row->created) + ->setCreated(Date::createIsoDate($row->created)) ->setAnswerId($row->answer_id) ->setIsVisible($row->is_visible === 'Y'); diff --git a/phpmyfaq/src/phpMyFAQ/Template/CategoryNameTwigExtension.php b/phpmyfaq/src/phpMyFAQ/Template/CategoryNameTwigExtension.php new file mode 100644 index 0000000000..406af36c69 --- /dev/null +++ b/phpmyfaq/src/phpMyFAQ/Template/CategoryNameTwigExtension.php @@ -0,0 +1,26 @@ +getCategoryName(...)), + ]; + } + + private function getCategoryName(int $categoryId): string + { + $category = new Category(Configuration::getConfigurationInstance()); + + $categoryData = $category->getCategoryData($categoryId); + return $categoryData->getName(); + } +}