1 | <?php |
||
2 | /* |
||
3 | * You may not change or alter any portion of this comment or credits |
||
4 | * of supporting developers from this source code or any supporting source code |
||
5 | * which is considered copyrighted (c) material of the original comment or credit authors. |
||
6 | * |
||
7 | * This program is distributed in the hope that it will be useful, |
||
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||
10 | */ |
||
11 | |||
12 | /** |
||
13 | * @copyright XOOPS Project (https://xoops.org) |
||
14 | * @license GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html) |
||
15 | * @package |
||
16 | * @since |
||
17 | * @author XOOPS Development Team |
||
18 | */ |
||
19 | |||
20 | use Xmf\Module\Admin; |
||
21 | use Xmf\Request; |
||
22 | use Xmf\Yaml; |
||
23 | use XoopsModules\Smartfaq\{ |
||
24 | Common, |
||
25 | Constants, |
||
26 | Helper, |
||
27 | Utility |
||
28 | }; |
||
29 | |||
30 | /** @var Admin $adminObject */ |
||
31 | /** @var Helper $helper */ |
||
32 | /** @var Utility $utility */ |
||
33 | |||
34 | require_once dirname(dirname(dirname(__DIR__))) . '/include/cp_header.php'; |
||
35 | require_once __DIR__ . '/admin_header.php'; |
||
36 | |||
37 | xoops_cp_header(); |
||
38 | |||
39 | $adminObject = \Xmf\Module\Admin::getInstance(); |
||
40 | |||
41 | //---------------------- |
||
42 | |||
43 | // Creating the category handler object |
||
44 | /** @var \XoopsModules\Smartfaq\CategoryHandler $categoryHandler */ |
||
45 | $categoryHandler = \XoopsModules\Smartfaq\Helper::getInstance()->getHandler('Category'); |
||
46 | |||
47 | // Creating the FAQ handler object |
||
48 | /** @var \XoopsModules\Smartfaq\FaqHandler $faqHandler */ |
||
49 | $faqHandler = \XoopsModules\Smartfaq\Helper::getInstance()->getHandler('Faq'); |
||
50 | |||
51 | // Total FAQs -- includes everything on the table |
||
52 | $totalfaqs = $faqHandler->getFaqsCount(); |
||
53 | |||
54 | // Total categories |
||
55 | $totalcategories = $categoryHandler->getCategoriesCount(-1); |
||
56 | |||
57 | // Total FAQ count by status |
||
58 | $totalfaqbystatus = $faqHandler->getFaqsCountByStatus(); |
||
59 | |||
60 | // Total asked FAQs |
||
61 | $totalasked = isset($totalfaqbystatus[Constants::SF_STATUS_ASKED]) ? $totalfaqbystatus[Constants::SF_STATUS_ASKED] : 0; |
||
62 | |||
63 | // Total opened FAQs |
||
64 | $totalopened = isset($totalfaqbystatus[Constants::SF_STATUS_OPENED]) ? $totalfaqbystatus[Constants::SF_STATUS_OPENED] : 0; |
||
65 | |||
66 | // Total answered FAQs |
||
67 | $totalanswered = isset($totalfaqbystatus[Constants::SF_STATUS_ANSWERED]) ? $totalfaqbystatus[Constants::SF_STATUS_ANSWERED] : 0; |
||
68 | |||
69 | // Total submitted FAQs |
||
70 | $totalsubmitted = isset($totalfaqbystatus[Constants::SF_STATUS_SUBMITTED]) ? $totalfaqbystatus[Constants::SF_STATUS_SUBMITTED] : 0; |
||
71 | |||
72 | // Total published FAQs |
||
73 | $totalpublished = isset($totalfaqbystatus[Constants::SF_STATUS_PUBLISHED]) ? $totalfaqbystatus[Constants::SF_STATUS_PUBLISHED] : 0; |
||
74 | |||
75 | // Total offline FAQs |
||
76 | $totaloffline = isset($totalfaqbystatus[Constants::SF_STATUS_OFFLINE]) ? $totalfaqbystatus[Constants::SF_STATUS_OFFLINE] : 0; |
||
77 | |||
78 | // Total rejected question |
||
79 | $totalrejectedquestion = isset($totalfaqbystatus[Constants::SF_STATUS_REJECTED_QUESTION]) ? $totalfaqbystatus[Constants::SF_STATUS_REJECTED_QUESTION] : 0; |
||
80 | |||
81 | // Total rejected smartfaq |
||
82 | $totalrejectedsmartfaq = isset($totalfaqbystatus[Constants::SF_STATUS_REJECTED_SMARTFAQ]) ? $totalfaqbystatus[Constants::SF_STATUS_REJECTED_SMARTFAQ] : 0; |
||
83 | |||
84 | // Total Q&A with new answers |
||
85 | $totalnewanswers = isset($totalfaqbystatus[Constants::SF_STATUS_NEW_ANSWER]) ? $totalfaqbystatus[Constants::SF_STATUS_NEW_ANSWER] : 0; |
||
86 | |||
87 | //set info block |
||
88 | $adminObject->addInfoBox(_AM_SF_INVENTORY); |
||
89 | |||
90 | if ($totalcategories > 0) { |
||
91 | $adminObject->addInfoBoxLine(sprintf('<infolabel>' . '<a href="category.php">' . _AM_SF_TOTALCAT . '</a><b>' . '</infolabel>', $totalcategories), '', 'Green'); |
||
92 | } else { |
||
93 | $adminObject->addInfoBoxLine(sprintf('<infolabel>' . _AM_SF_TOTALCAT . '</infolabel>', $totalcategories), '', 'Green'); |
||
94 | } |
||
95 | if ($totalasked > 0) { |
||
96 | $adminObject->addInfoBoxLine(sprintf('<infolabel>' . '<a href="main.php">' . _AM_SF_TOTALASKED . '</a><b>' . '</infolabel>', $totalasked), '', 'Green'); |
||
97 | } else { |
||
98 | $adminObject->addInfoBoxLine(sprintf('<infolabel>' . _AM_SF_TOTALASKED . '</infolabel>', $totalasked), '', 'Green'); |
||
99 | } |
||
100 | if ($totalopened > 0) { |
||
101 | $adminObject->addInfoBoxLine(sprintf('<infolabel>' . '<a href="question.php">' . _AM_SF_TOTALOPENED . '</a><b>' . '</infolabel>', $totalopened), '', 'Red'); |
||
102 | } else { |
||
103 | $adminObject->addInfoBoxLine(sprintf('<infolabel>' . _AM_SF_TOTALOPENED . '</infolabel>', $totalopened), '', 'Green'); |
||
104 | } |
||
105 | if ($totalsubmitted > 0) { |
||
106 | $adminObject->addInfoBoxLine(sprintf('<infolabel>' . '<a href="category.php">' . _AM_SF_TOTALSUBMITTED . '</a><b>' . '</infolabel>', $totalsubmitted), '', 'Green'); |
||
107 | } else { |
||
108 | $adminObject->addInfoBoxLine(sprintf('<infolabel>' . _AM_SF_TOTALSUBMITTED . '</infolabel>', $totalsubmitted), '', 'Green'); |
||
109 | } |
||
110 | if ($totalpublished > 0) { |
||
111 | $adminObject->addInfoBoxLine(sprintf('<infolabel>' . '<a href="faq.php">' . _AM_SF_TOTALPUBLISHED . '</a><b>' . '</infolabel>', $totalpublished), '', 'Green'); |
||
112 | } else { |
||
113 | $adminObject->addInfoBoxLine(sprintf('<infolabel>' . _AM_SF_TOTALPUBLISHED . '</infolabel>', $totalpublished), '', 'Green'); |
||
114 | } |
||
115 | if ($totalnewanswers > 0) { |
||
116 | $adminObject->addInfoBoxLine(sprintf('<infolabel>' . '<a href="main.php">' . _AM_SF_TOTALNEWANSWERS . '</a><b>' . '</infolabel>', $totalnewanswers), '', 'Red'); |
||
117 | } else { |
||
118 | $adminObject->addInfoBoxLine(sprintf('<infolabel>' . _AM_SF_TOTALNEWANSWERS . '</infolabel>', $totalnewanswers), '', 'Green'); |
||
119 | } |
||
120 | |||
121 | //---------------------- |
||
122 | |||
123 | $adminObject->displayNavigation(basename(__FILE__)); |
||
124 | |||
125 | //check for latest release |
||
126 | //$newRelease = $utility->checkVerModule($helper); |
||
127 | //if (!empty($newRelease)) { |
||
128 | // $adminObject->addItemButton($newRelease[0], $newRelease[1], 'download', 'style="color : Red"'); |
||
129 | //} |
||
130 | |||
131 | //------------- Test Data ---------------------------- |
||
132 | |||
133 | if ($helper->getConfig('displaySampleButton')) { |
||
134 | $yamlFile = dirname(__DIR__) . '/config/admin.yml'; |
||
135 | $config = loadAdminConfig($yamlFile); |
||
136 | $displaySampleButton = $config['displaySampleButton']; |
||
137 | |||
138 | if (1 == $displaySampleButton) { |
||
139 | xoops_loadLanguage('admin/modulesadmin', 'system'); |
||
140 | require_once dirname(__DIR__) . '/testdata/index.php'; |
||
141 | |||
142 | $adminObject->addItemButton(constant('CO_' . $moduleDirNameUpper . '_' . 'ADD_SAMPLEDATA'), '__DIR__ . /../../testdata/index.php?op=load', 'add'); |
||
143 | $adminObject->addItemButton(constant('CO_' . $moduleDirNameUpper . '_' . 'SAVE_SAMPLEDATA'), '__DIR__ . /../../testdata/index.php?op=save', 'add'); |
||
144 | // $adminObject->addItemButton(constant('CO_' . $moduleDirNameUpper . '_' . 'EXPORT_SCHEMA'), '__DIR__ . /../../testdata/index.php?op=exportschema', 'add'); |
||
145 | $adminObject->addItemButton(constant('CO_' . $moduleDirNameUpper . '_' . 'HIDE_SAMPLEDATA_BUTTONS'), '?op=hide_buttons', 'delete'); |
||
146 | } else { |
||
147 | $adminObject->addItemButton(constant('CO_' . $moduleDirNameUpper . '_' . 'SHOW_SAMPLEDATA_BUTTONS'), '?op=show_buttons', 'add'); |
||
148 | $displaySampleButton = $config['displaySampleButton']; |
||
149 | } |
||
150 | $adminObject->displayButton('left', ''); |
||
151 | } |
||
152 | |||
153 | //------------- End Test Data ---------------------------- |
||
154 | |||
155 | $adminObject->displayIndex(); |
||
156 | |||
157 | /** |
||
158 | * @param $yamlFile |
||
159 | * @return array|bool |
||
160 | */ |
||
161 | function loadAdminConfig($yamlFile) |
||
162 | { |
||
163 | $config = Yaml::readWrapped($yamlFile); // work with phpmyadmin YAML dumps |
||
164 | return $config; |
||
165 | } |
||
166 | |||
167 | /** |
||
168 | * @param $yamlFile |
||
169 | */ |
||
170 | function hideButtons($yamlFile) |
||
171 | { |
||
172 | $app['displaySampleButton'] = 0; |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Loading history...
|
|||
173 | Yaml::save($app, $yamlFile); |
||
174 | redirect_header('index.php', 0, ''); |
||
175 | } |
||
176 | |||
177 | /** |
||
178 | * @param $yamlFile |
||
179 | */ |
||
180 | function showButtons($yamlFile) |
||
181 | { |
||
182 | $app['displaySampleButton'] = 1; |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
183 | Yaml::save($app, $yamlFile); |
||
184 | redirect_header('index.php', 0, ''); |
||
185 | } |
||
186 | |||
187 | $op = Request::getString('op', 0, 'GET'); |
||
188 | |||
189 | switch ($op) { |
||
190 | case 'hide_buttons': |
||
191 | hideButtons($yamlFile); |
||
192 | break; |
||
193 | case 'show_buttons': |
||
194 | showButtons($yamlFile); |
||
195 | break; |
||
196 | } |
||
197 | |||
198 | echo $utility::getServerStats(); |
||
199 | |||
200 | require __DIR__ . '/admin_footer.php'; |
||
201 |