1<?php
2/**
3 * View a generated report.
4 *
5 *
6 *
7 * This Source Code Form is subject to the terms of the Mozilla Public License,
8 * v. 2.0. If a copy of the MPL was not distributed with this file, You can
9 * obtain one at http://mozilla.org/MPL/2.0/.
10 *
11 * @package phpMyFAQ
12 * @author Gustavo Solt <gustavo.solt@mayflower.de>
13 * @author Thorsten Rinne <thorsten@phpmyfaq.de>
14 * @copyright 2011-2020 phpMyFAQ Team
15 * @license http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
16 * @link https://www.phpmyfaq.de
17 * @since 2011-01-12
18 */
19
20use phpMyFAQ\Filter;
21use phpMyFAQ\Report;
22
23if (!defined('IS_VALID_PHPMYFAQ')) {
24    http_response_code(400);
25    exit();
26}
27?>
28        <header class="row">
29            <div class="col-lg-12">
30                <h2 class="page-header"><i aria-hidden="true" class="fa fa-tasks"></i>  <?= $PMF_LANG['ad_menu_reports']; ?></h2>
31            </div>
32        </header>
33
34
35        <div class="row">
36            <div class="col-lg-12">
37<?php
38if ($user->perm->checkRight($user->getUserId(), 'reports')) {
39    $useCategory = Filter::filterInput(INPUT_POST, 'report_category', FILTER_VALIDATE_INT);
40    $useSubcategory = Filter::filterInput(INPUT_POST, 'report_sub_category', FILTER_VALIDATE_INT);
41    $useTranslation = Filter::filterInput(INPUT_POST, 'report_translations', FILTER_VALIDATE_INT);
42    $useLanguage = Filter::filterInput(INPUT_POST, 'report_language', FILTER_VALIDATE_INT);
43    $useId = Filter::filterInput(INPUT_POST, 'report_id', FILTER_VALIDATE_INT);
44    $useSticky = Filter::filterInput(INPUT_POST, 'report_sticky', FILTER_VALIDATE_INT);
45    $useTitle = Filter::filterInput(INPUT_POST, 'report_title', FILTER_VALIDATE_INT);
46    $useCreationDate = Filter::filterInput(INPUT_POST, 'report_creation_date', FILTER_VALIDATE_INT);
47    $useOwner = Filter::filterInput(INPUT_POST, 'report_owner', FILTER_VALIDATE_INT);
48    $useLastModified = Filter::filterInput(INPUT_POST, 'report_last_modified_person', FILTER_VALIDATE_INT);
49    $useUrl = Filter::filterInput(INPUT_POST, 'report_url', FILTER_VALIDATE_INT);
50    $useVisits = Filter::filterInput(INPUT_POST, 'report_visits', FILTER_VALIDATE_INT);
51    ?>
52                <table class="table table-striped">
53                    <thead>
54                        <tr>
55<?php
56    ($useCategory) ? printf('<th>%s</th>', $PMF_LANG['ad_stat_report_category']) : '';
57    ($useSubcategory) ? printf('<th>%s</th>', $PMF_LANG['ad_stat_report_sub_category']) : '';
58    ($useTranslation) ? printf('<th>%s</th>', $PMF_LANG['ad_stat_report_translations']) : '';
59    ($useLanguage) ? printf('<th>%s</th>', $PMF_LANG['ad_stat_report_language']) : '';
60    ($useId) ? printf('<th>%s</th>', $PMF_LANG['ad_stat_report_id']) : '';
61    ($useSticky) ? printf('<th>%s</th>', $PMF_LANG['ad_stat_report_sticky']) : '';
62    ($useTitle) ? printf('<th>%s</th>', $PMF_LANG['ad_stat_report_title']) : '';
63    ($useCreationDate) ? printf('<th>%s</th>', $PMF_LANG['ad_stat_report_creation_date']) : '';
64    ($useOwner) ? printf('<th>%s</th>', $PMF_LANG['ad_stat_report_owner']) : '';
65    ($useLastModified) ? printf('<th>%s</th>', $PMF_LANG['ad_stat_report_last_modified_person']) : '';
66    ($useUrl) ? printf('<th>%s</th>', $PMF_LANG['ad_stat_report_url']) : '';
67    ($useVisits) ? printf('<th>%s</th>', $PMF_LANG['ad_stat_report_visits']) : '';
68    ?>
69                        </tr>
70                    </thead>
71                    <tbody>
72<?php
73
74    $report = new Report($faqConfig);
75
76    foreach ($report->getReportingData() as $data) {
77        echo '<tr>';
78        if ($useCategory) {
79            if (0 != $data['category_parent']) {
80                printf('<td>%s</td>', $data['category_parent']);
81            } else {
82                printf('<td>%s</td>', $data['category_name']);
83            }
84        }
85        if ($useSubcategory) {
86            if (0 != $data['category_parent']) {
87                printf('<td>%s</td>', $data['category_name']);
88            } else {
89                echo '<td>n/a</td>';
90            }
91        }
92        if ($useTranslation) {
93            printf('<td>%d</td>', $data['faq_translations']);
94        }
95        if ($useLanguage && isset($languageCodes[strtoupper($data['faq_language'])])) {
96            printf('<td>%s</td>', $languageCodes[strtoupper($data['faq_language'])]);
97        }
98        if ($useId) {
99            printf('<td>%d</td>', $data['faq_id']);
100        }
101        if ($useSticky) {
102            printf('<td>%s</td>', $data['faq_sticky']);
103        }
104        if ($useTitle) {
105            printf('<td>%s</td>', $data['faq_question']);
106        }
107        if ($useCreationDate) {
108            printf('<td>%s</td>', $data['faq_updated']);
109        }
110        if ($useOwner) {
111            printf('<td>%s</td>', $data['faq_org_author']);
112        }
113        if ($useLastModified) {
114            printf('<td>%s</td>', $data['faq_last_author']);
115        }
116        if ($useUrl) {
117            $url = sprintf('<a href="../index.php?action=faq&amp;cat=%d&amp;id=%d&amp;artlang=%s">Link</a>',
118                $data['category_id'],
119                $data['faq_id'],
120                $data['faq_language']
121            );
122            printf('<td>%s</td>', $url);
123        }
124        if ($useVisits) {
125            printf('<td>%d</td>', $data['faq_visits']);
126        }
127        echo '</tr>';
128    }
129    ?>
130                    </tbody>
131                </table>
132                <form action="?action=reportexport" method="post" accept-charset="utf-8">
133                    <input type="hidden" name="report_category" id="report_category" value="<?= $useCategory ?>"></td>
134                    <input type="hidden" name="report_sub_category" id="report_sub_category" value="<?= $useSubcategory ?>"></td>
135                    <input type="hidden" name="report_translations" id="report_translations" value="<?= $useTranslation ?>"></td>
136                    <input type="hidden" name="report_language" id="report_language" value="<?= $useLanguage ?>"></td>
137                    <input type="hidden" name="report_id" id="report_id" value="<?= $useId ?>"></td>
138                    <input type="hidden" name="report_sticky" id="report_sticky" value="<?= $useSticky ?>"></td>
139                    <input type="hidden" name="report_title" id="report_title" value="<?= $useTitle ?>"></td>
140                    <input type="hidden" name="report_creation_date" id="report_creation_date" value="<?= $useCreationDate ?>"></td>
141                    <input type="hidden" name="report_owner" id="report_owner" value="<?= $useOwner ?>"></td>
142                    <input type="hidden" name="report_last_modified_person" id="report_last_modified_person" class="radio" value="<?= $useLastModified ?>">
143                    <input type="hidden" name="report_url" id="report_url" value="<?= $useUrl ?>"></td>
144                    <input type="hidden" name="report_visits" id="report_visits" value="<?= $useVisits ?>"></td>
145                    <div class="form-group row">
146                        <button class="btn btn-primary" type="submit">
147                            <?= $PMF_LANG['ad_stat_report_make_csv'] ?>
148                        </button>
149                    </div>
150                </form>
151<?php
152
153} else {
154    echo $PMF_LANG['err_NotAuth'];
155}
156?>
157            </div>
158        </div>
159