Completed
Pull Request — master (#7)
by Michael
01:37
created

admin/main.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * xLanguage module (eXtensible Language Management For XOOPS)
4
 *
5
 * You may not change or alter any portion of this comment or credits
6
 * of supporting developers from this source code or any supporting source code
7
 * which is considered copyrighted (c) material of the original comment or credit authors.
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * @copyright    XOOPS Project (https://xoops.org)
13
 * @license      {@link http://www.gnu.org/licenses/gpl-2.0.html GNU Public License}
14
 * @package      xlanguage
15
 * @since        2.0
16
 * @author       D.J.(phppp) [email protected]
17
 **/
18
19
require_once __DIR__ . '/../../../include/cp_header.php';
20
require_once __DIR__ . '/admin_header.php';
21
22
require_once XOOPS_ROOT_PATH . '/modules/xlanguage/include/vars.php';
23
require_once XOOPS_ROOT_PATH . '/modules/xlanguage/include/functions.php';
24
25
$op = '';
26
if (isset($_POST)) {
27
    foreach ($_POST as $k => $v) {
28
        ${$k} = $v;
29
    }
30
}
31
if (isset($_GET)) {
32
    foreach ($_GET as $k => $v) {
33
        ${$k} = $v;
34
    }
35
}
36
37
define('XLANG_CONFIG_LINK', "<a href='main.php' target='_self'>" . _AM_XLANG_CONFIG . '</a>');
38
39
$xlanguageHandler = xoops_getModuleHandler('language', 'xlanguage');
40
$xlanguageHandler->loadConfig();
41
42
switch ($op) {
43
    case 'del':
44
        if (!isset($_POST['ok']) || $_POST['ok'] != 1) {
45
            xoops_cp_header();
46
            $aboutAdmin = \Xmf\Module\Admin::getInstance();
47
            $adminObject->displayNavigation(basename(__FILE__));
48
            //            echo "<h4>" . XLANG_CONFIG_LINK . "</h4>";
49
            xoops_confirm(array('op' => 'del', 'type' => $_GET['type'], 'lang_id' => (int)$_GET['lang_id'], 'ok' => 1), 'main.php', _AM_XLANG_DELETE_CFM);
50
        } else {
51
            $isBase = true;
52
            if (isset($type) && $type === 'ext') {
53
                $isBase = false;
54
            }
55
            $lang = $xlanguageHandler->get($lang_id, $isBase);
56
            $xlanguageHandler->delete($lang);
57
            redirect_header('main.php', 2, _AM_XLANG_DELETED);
58
        }
59
        break;
60
61
    case 'save':
62
        $isBase = true;
63
        if (isset($type) && $type === 'ext') {
64
            $isBase = false;
65
        }
66
        if (isset($lang_id) && $lang_id > 0) {
67
            $lang = $xlanguageHandler->get($lang_id, $isBase);
68
        } else {
69
            $lang = $xlanguageHandler->create(true, $isBase);
70
        }
71
        $lang_name = preg_replace("/[^a-zA-Z0-9\_\-]/", '', $lang_name);
72
73
        $lang->setVar('lang_name', $lang_name);
74
        $lang->setVar('lang_desc', $lang_desc);
75
        $lang->setVar('lang_code', $lang_code);
76
        $lang->setVar('lang_charset', $lang_charset);
77
        $lang->setVar('lang_image', $lang_image);
78
        if (!$isBase) {
79
            $lang->setVar('lang_base', $lang_base);
80
        }
81
        $lang->setVar('weight', $weight);
82
        $xlanguageHandler->insert($lang);
83
        redirect_header('main.php', 2, _AM_XLANG_SAVED);
84
        break;
85
86
    case 'edit':
87
        xoops_cp_header();
88
        $aboutAdmin = \Xmf\Module\Admin::getInstance();
89
        $adminObject->displayNavigation(basename(__FILE__));
90
        // echo "<h4>" . XLANG_CONFIG_LINK . "</h4>";
91
        // echo "<br>";
92
        echo '<h4>' . _AM_XLANG_EDITLANG . '</h4>';
93
        $isBase = true;
94
        if (isset($type) && $type === 'ext') {
95
            $isBase = false;
96
        }
97
        if (isset($lang_id) && $lang_id > 0) {
98
            $lang = $xlanguageHandler->get($lang_id, $isBase);
99
        } elseif (isset($lang_name)) {
100
            $lang = $xlanguageHandler->getByName($lang_name, $isBase);
101
        } else {
102
            $lang = $xlanguageHandler->create(true, $isBase);
103
        }
104
        $lang_name    = $lang->getVar('lang_name');
105
        $lang_desc    = $lang->getVar('lang_desc');
106
        $lang_code    = $lang->getVar('lang_code');
107
        $lang_charset = $lang->getVar('lang_charset');
108
        $lang_image   = $lang->getVar('lang_image');
109
        $weight       = $lang->getVar('weight');
110
        if (!$isBase) {
111
            $lang_base = $lang->getVar('lang_base');
112
        }
113
        include __DIR__ . '/langform.inc.php';
114
        break;
115
116
    case 'add':
117
        xoops_cp_header();
118
        $aboutAdmin = \Xmf\Module\Admin::getInstance();
119
        //        echo "<h4>" . XLANG_CONFIG_LINK . "</h4>";
120
        //        echo "<br>";
121
        //        echo "<h4>" . _AM_XLANG_ADDLANG . "</h4>";
122
        if (isset($type) && $type === 'ext') {
123
            $isBase = false;
124
            $adminObject->displayNavigation('main.php?op=add&type=ext');
125
        } else {
126
            $isBase = true;
127
            $adminObject->displayNavigation('main.php?op=add&type=base');
128
        }
129
        $lang_name    = '';
130
        $lang_desc    = '';
131
        $lang_code    = '';
132
        $lang_charset = '';
133
        $lang_image   = '';
134
        $weight       = 1;
135
        $lang_base    = '';
136
        include __DIR__ . '/langform.inc.php';
137
        break;
138
139
    case 'createconfig':
140
        xlanguage_createConfig();
141
        redirect_header('main.php', 1, _AM_XLANG_CREATED);
142
143
        break;
144
145
    case 'default':
146
    default:
147
        xoops_cp_header();
148
        $adminObject = \Xmf\Module\Admin::getInstance();
149
        $adminObject->displayNavigation(basename(__FILE__));
150
151
        // if (TDMDownloads_checkModuleAdmin()) {
152
        // $adminObject = \Xmf\Module\Admin::getInstance();
0 ignored issues
show
Unused Code Comprehensibility introduced by
46% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
153
        // $adminObject->displayNavigation('downloads.php');
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
154
        $adminObject->addItemButton(_MI_XLANGUAGE_ADMENU1, 'main.php?op=add&type=base', 'add');
155
        $adminObject->addItemButton(_MI_XLANGUAGE_ADMENU2, 'main.php?op=add&type=ext', 'insert_table_row');
156
157
        $adminObject->displayButton('left');
158
        //        }
159
160
        //        echo "<h4>" . XLANG_CONFIG_LINK . "</h4>";
161
        languageList();
162
        $configfile_status = (@is_readable(XLANGUAGE_CONFIG_FILE)) ? _AM_XLANG_CONFIGOK : _AM_XLANG_CONFIGNOTOK;
163
        echo "<table width='100%' border='0' cellspacing='1' class='outer'><tr><td class=\"odd\"><br>";
164
        //        echo " - <b><a href='index.php?op=add&amp;type=base'>" . _AM_XLANG_ADDBASE . "</a></b><br><br>\n";
165
        //        echo " - <b><a href='index.php?op=add&amp;type=ext'>" . _AM_XLANG_ADDEXT . "</a></b><br><br>\n";
166
        echo '<b>' . $configfile_status . '</b>: ' . XLANGUAGE_CONFIG_FILE . " (<a href='main.php?op=createconfig' title='" . _AM_XLANG_CREATECONFIG . "'>" . _AM_XLANG_CREATECONFIG . "</a>)<br><br>\n";
167
        //        echo " - <b><a href='about.php'>" . _AM_XLANG_ABOUT . "</a></b>";
168
        echo '</td></tr></table>';
169
        break;
170
}
171
xoops_cp_footer();
172
173
function languageList()
174
{
175
    global $xlanguageHandler, $xoopsModule;
176
177
    global $pathIcon16;
178
179
    $lang_list = $xlanguageHandler->getAllList();
180
    if (is_array($lang_list) && count($lang_list) > 0) {
181
        echo "<table width='100%' border='0' cellspacing='1' class='outer'><tr><td class=\"odd\">";
182
        echo "<div style='text-align: center;'><b><h4>" . _AM_XLANG_LANGLIST . '</h4></b><br>';
183
        echo "<table class='outer' width='100%' border='0' cellpadding='0' cellspacing='0' ><tr class='bg2'><th align='center'>"
184
             . _AM_XLANG_DESC
185
             . "</th><th align='center'>"
186
             . _AM_XLANG_NAME
187
             . "</th><th align='center'>"
188
             . _AM_XLANG_CHARSET
189
             . "</th><th align='center'>"
190
             . _AM_XLANG_CODE
191
             . "</th><th align='center'>"
192
             . _AM_XLANG_IMAGE
193
             . "</th><th align='center'>"
194
             . _AM_XLANG_WEIGHT
195
             . "</th><th align='center'>"
196
             . _AM_XLANG_BASE
197
             . "</th><th align='center'>"
198
             . _AM_XLANG_ACTION
199
             . "</th></tr>\n";
200
        $class = 'even';
201
        foreach (array_keys($lang_list) as $lang_name) {
202
            $lang     =& $lang_list[$lang_name];
203
            $isOrphan = true;
204
            if (isset($lang['base'])) {
205
                echo "<tr>\n";
206
                echo "<td class='$class' >" . $lang['base']->getVar('lang_desc') . "</td>\n";
207
                echo "<td class='$class' ><b>" . $lang['base']->getVar('lang_name') . "</b></td>\n";
208
                echo "<td class='$class' ><b>" . $lang['base']->getVar('lang_charset') . "</b></td>\n";
209
                echo "<td class='$class' >" . $lang['base']->getVar('lang_code') . "</td>\n";
210
                $lang_image = 'noflag.gif';
211 View Code Duplication
                if (is_readable(XOOPS_ROOT_PATH . '/modules/xlanguage/assets/images/' . $lang['base']->getVar('lang_image'))) {
212
                    $lang_image = $lang['base']->getVar('lang_image');
213
                }
214
                echo "<td class='$class' ><img src='" . XOOPS_URL . '/modules/xlanguage/assets/images/' . $lang_image . "' alt='" . $lang['base']->getVar('lang_desc') . "'></td>\n";
215
                echo "<td class='$class' >" . $lang['base']->getVar('weight') . "</td>\n";
216
                echo "<td class='$class' >&#216;</td>\n";
217
                echo "<td class='$class' ><a href='main.php?op=edit&amp;type=base&amp;lang_id="
218
                     . $lang['base']->getVar('lang_id')
219
                     . "'><img src="
220
                     . $pathIcon16
221
                     . '/edit.png title='
222
                     . _EDIT
223
                     . "></a>\n"
224
                     . "<a href='main.php?op=del&amp;type=base&amp;lang_id="
225
                     . $lang['base']->getVar('lang_id')
226
                     . "'><img src="
227
                     . $pathIcon16
228
                     . '/delete.png title='
229
                     . _DELETE
230
                     . "></td>\n";
231
                echo "</tr>\n";
232
                $isOrphan = false;
233
                $class    = ($class === 'odd') ? 'even' : 'odd';
234
            }
235
            if (!isset($lang['ext']) || count($lang['ext']) < 1) {
236
                continue;
237
            }
238
            foreach ($lang['ext'] as $ext) {
239
                echo "<tr>\n";
240
                echo "<td class='$class' >" . $ext->getVar('lang_desc') . "</td>\n";
241
                echo "<td class='$class' >" . $ext->getVar('lang_name') . "</td>\n";
242
                echo "<td class='$class' ><b>" . $ext->getVar('lang_charset') . "</b></td>\n";
243
                echo "<td class='$class' >" . $ext->getVar('lang_code') . "</td>\n";
244
                $lang_image = 'noflag.gif';
245 View Code Duplication
                if (is_readable(XOOPS_ROOT_PATH . '/modules/xlanguage/assets/images/' . $ext->getVar('lang_image'))) {
246
                    $lang_image = $ext->getVar('lang_image');
247
                }
248
                echo "<td class='$class' ><img src='" . XOOPS_URL . '/modules/xlanguage/assets/images/' . $lang_image . "' alt='" . $ext->getVar('lang_desc') . "'></td>\n";
249
                echo "<td class='$class' >" . $ext->getVar('weight') . "</td>\n";
250
                $lang_base = $isOrphan ? "<font color='red'>" . $ext->getVar('lang_base') . '</font>' : $ext->getVar('lang_base');
251
                echo "<td class='$class' ><b>" . $lang_base . "</b></td>\n";
252
                echo "<td class='$class' ><a href='main.php?op=edit&amp;type=ext&amp;lang_id="
253
                     . $ext->getVar('lang_id')
254
                     . "'><img src="
255
                     . $pathIcon16
256
                     . '/edit.png title='
257
                     . _EDIT
258
                     . "></a>\n"
259
                     . "<a href='main.php?op=del&amp;type=ext&amp;lang_id="
260
                     . $ext->getVar('lang_id')
261
                     . "'><img src="
262
                     . $pathIcon16
263
                     . '/delete.png title='
264
                     . _DELETE
265
                     . "></td>\n";
266
                echo "</tr>\n";
267
            }
268
            echo "<tr><td colspan='9' ></td></tr>\n";
269
            $class = ($class === 'odd') ? 'even' : 'odd';
270
        }
271
272
        echo "</table></div>\n";
273
        echo '</td></tr></table>';
274
        echo '<br>';
275
    }
276
}
277