Completed
Push — master ( c1777d...d193e2 )
by Michael
13:22
created

functions.php ➔ lx_save_Permissions()   B

Complexity

Conditions 3
Paths 2

Size

Total Lines 24
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 11
nc 2
nop 3
dl 0
loc 24
rs 8.9713
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 30 and the first side effect is on line 12.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 *
4
 * Module: lexikon
5
 * Version: v 1.00
6
 * Release Date: 18 Dec 2011
7
 * Author: Yerres
8
 * Licence: GNU
9
 */
10
11 View Code Duplication
if (is_object($xoopsUser)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
12
    $xoopsModule = XoopsModule::getByDirname('lexikon');
13
    if (!$xoopsUser->isAdmin($xoopsModule->mid())) {
14
        redirect_header(XOOPS_URL . '/', 1, _NOPERM);
15
    }
16
} else {
17
    redirect_header(XOOPS_URL . '/', 1, _NOPERM);
18
}
19
/**
20
 * Function used to display an horizontal menu inside the admin panel
21
 * Enable webmasters to navigate thru the module's features.
22
 * Each time you select an option in the admin panel of the news module, this option is highlighted in this menu
23
 * @package          lexikon
24
 * @orig             author: hsalazar, The smartfactory
25
 * @copyright    (c) XOOPS Project (http://xoops.org)
26
 * @param int    $currentoption
27
 * @param string $breadcrumb
28
 */
29
30
function lx_adminMenu($currentoption = 0, $breadcrumb = '')
31
{
32
    include_once XOOPS_ROOT_PATH . '/class/template.php';
33
34
    global $xoopsDB, $xoopsModule, $xoopsConfig;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
35 View Code Duplication
    if (file_exists(XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->dirname() . '/language/' . $xoopsConfig['language'] . '/modinfo.php')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
36
        include_once XOOPS_ROOT_PATH . '/modules/lexikon/language/' . $xoopsConfig['language'] . '/modinfo.php';
37
    } else {
38
        include_once XOOPS_ROOT_PATH . '/modules/lexikon/language/english/modinfo.php';
39
    }
40 View Code Duplication
    if (file_exists(XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->dirname() . '/language/' . $xoopsConfig['language'] . '/admin.php')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
41
        include_once XOOPS_ROOT_PATH . '/modules/lexikon/language/' . $xoopsConfig['language'] . '/admin.php';
42
    } else {
43
        include_once XOOPS_ROOT_PATH . '/modules/lexikon/language/english/admin.php';
44
    }
45
46
    include __DIR__ . '/menu.php';
47
48
    $tpl = new XoopsTpl();
49
    $tpl->assign(array(
50
                     'headermenu'      => $headermenu,
0 ignored issues
show
Bug introduced by
The variable $headermenu does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
51
                     'adminmenu'       => $adminmenu,
0 ignored issues
show
Bug introduced by
The variable $adminmenu does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
52
                     'current'         => $currentoption,
53
                     'breadcrumb'      => $breadcrumb,
54
                     'headermenucount' => count($headermenu)
55
                 ));
56
    $tpl->display('db:lx_adminmenu.tpl');
57
    echo "<br>\n";
58
}
59
60
/**
61
 * Verify that a field exists inside a mysql table
62
 *
63
 * @package       Lexikon
64
 * @author        Instant Zero (http://xoops.instant-zero.com)
65
 * @copyright (c) Instant Zero
66
 * @param $fieldname
67
 * @param $table
68
 * @return bool
69
 */
70
function lx_FieldExists($fieldname, $table)
71
{
72
    global $xoopsDB;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
73
    $result = $xoopsDB->queryF("SHOW COLUMNS FROM   $table LIKE '$fieldname'");
74
75
    return ($xoopsDB->getRowsNum($result) > 0);
76
}
77
78
/**
79
 * Add a field to a mysql table
80
 *
81
 * @package       Lexikon
82
 * @author        Instant Zero (http://xoops.instant-zero.com)
83
 * @copyright (c) Instant Zero
84
 * @param $field
85
 * @param $table
86
 * @return
87
 */
88
89
function lx_AddField($field, $table)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
90
{
91
    global $xoopsDB;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
92
    //naja !
93
    $result = $xoopsDB->queryF('ALTER TABLE ' . $table . ' ADD ' . $field . '');
94
95
    return $result;
96
}
97
98
/**
99
 * Change a field to a mysql table
100
 * desuet
101
 * @package       Lexikon
102
 * @author        Instant Zero (http://xoops.instant-zero.com)
103
 * @copyright (c) Instant Zero
104
 * @param $field
105
 * @param $table
106
 * @return bool
107
 */
108
109
function lx_alterTable($field, $table)
110
{
111
    global $xoopsDB;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
112
    $sql    = 'SHOW COLUMNS FROM ' . $table . " LIKE '" . $field . "'";
113
    $result = $xoopsDB->queryF($sql);
114
    //if ($result) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% 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...
115
    if ($xoopsDB->getRowsNum($result) == 0) {
116
        $sql = 'ALTER TABLE ' . $xoopsDB->prefix($table) . ' ADD `' . $field . '`';
117
118
        return $xoopsDB->query($sql);
119
        //   }
120
    }
121
122
    return true;
123
}
124
125
/*
126
 * Sub-Menu for Importscripts
127
 * @package lexikon
128
 * @copyright (c) XOOPS Project (http://xoops.org)
129
*/
130
131
/**
132
 * @param int    $currentoption
133
 * @param string $breadcrumb
134
 */
135
function lx_importMenu($currentoption = 0, $breadcrumb = '')
0 ignored issues
show
Unused Code introduced by
The parameter $currentoption is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $breadcrumb is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
136
{
137
    global $cf;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
138
    echo "<style type=\"text/css\">
139
    br {clear: left;}
140
    img {border:0;}
141
    #menu {width:400px; position:relative;  height:80px; margin:1em auto auto 2em;}
142
    #menu a:visited, #menu a {text-decoration:none; color:#d00; font-weight:bold;}
143
    #menu a:visited img, #menu a img{filter: alpha(opacity=40);
144
    filter: progid:DXImageTransform.Microsoft.Alpha(opacity=40);
145
    -moz-opacity: 0.40; opacity:0.4;
146
}
147
    #menu a:hover {background-color:trans; color:#06a;}
148
    #menu a span {display:none;}
149
    #menu a:hover span {display:block; position:absolute; top:50px; left:0; font-size:12px; height:18px; padding:4px; font-weight:normal; color:#a40;}
150
151
    #menu a:hover img { filter: alpha(opacity=100);
152
    filter: progid:DXImageTransform.Microsoft.Alpha(opacity=100);
153
    -moz-opacity: 1.00; opacity:1;
154
}
155
    </style>";
156
    echo " <TABLE BORDER=0 CELLPADDING=1 CELLSPACING=2 width='98%'>
157
    <tr><td width='200' VALIGN='top'>
158
    <h3>Import Menu</h3><span style='font-size:1'>";
159
    if ($cf < 5) {
160
        echo '' . _AM_LEXIKON_OTHERMODS . '';
161
    } else {
162
        echo '' . _AM_LEXIKON_NOOTHERMODS . '';
163
    }
164
165
    echo "</FONT></td><td VALIGN='top'>
166
    <div id=\"menu\">";
167
    // show only modules located on the system
168
    /** @var XoopsModuleHandler $moduleHandler */
169
    $moduleHandler = xoops_getHandler('module');
170
    $wordbookModule = $moduleHandler->getByDirname('wordbook');
171
    $got_options    = false;
0 ignored issues
show
Unused Code introduced by
$got_options is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
172
    $cf             = 0;
173
    if (is_object($wordbookModule)) {
174
        $wb_imgurl = XOOPS_URL . '/modules/wordbook/images';
175
        ++$cf;
176
        echo "<a href=\"importwordbook.php\">
177
        <img src=\"" . $wb_imgurl . "/wb_slogo.png\" alt=\"wb_slogo.png\" title=\"Wordbook\" height=\"39\" width=\"69\"><span>Import Wordbook</span></a>";
178
    } //else { echo "". 'wordbook' ."";}
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% 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...
179
    $dictionaryModule = $moduleHandler->getByDirname('dictionary');
180
    $got_options      = false;
0 ignored issues
show
Unused Code introduced by
$got_options is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
181
    if (is_object($dictionaryModule)) {
182
        $dic_imgurl = XOOPS_URL . '/modules/dictionary/images';
183
        ++$cf;
184
        echo "<a href=\"importdictionary.php\">
185
        <img src=\"" . $dic_imgurl . "/dictionary_logo.png\" alt=\"Dictionary\" title=\"Dictionary\" height=\"39\" width=\"69\"><span>Import Dictionary</span></a>";
186
    } //else { echo "<B>&middot;</B>". 'dictionary' ."";}
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% 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...
187
    $glossaireModule = $moduleHandler->getByDirname('glossaire');
188
    $got_options     = false;
0 ignored issues
show
Unused Code introduced by
$got_options is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
189
    if (is_object($glossaireModule)) {
190
        $glo_imgurl = XOOPS_URL . '/modules/glossaire.';
191
        ++$cf;
192
        echo "<a href=\"importglossaire.php\">
193
        <img src=\"" . $glo_imgurl . "/glossaire_logo.jpg\" alt=\"Glossaire\" title=\"Glossaire\" height=\"31\" width=\"88\"><span>Import Glossaire</span></a>";
194
    } //else { echo "<B>&middot;</B>". 'glossaire' ."";}
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% 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...
195
    $wiwimodModule = $moduleHandler->getByDirname('wiwimod');
196
    $got_options   = false;
0 ignored issues
show
Unused Code introduced by
$got_options is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
197
    if (is_object($wiwimodModule)) {
198
        $wiwi_imgurl = XOOPS_URL . '/modules/wiwimod/images';
199
        ++$cf;
200
        echo "<a href=\"importwiwimod.php\"><img src=\"" . $wiwi_imgurl . "/wiwilogo.gif\" alt=\"Wiwimod\" title=\"Wiwimod\" height=\"39\" width=\"69\"><span>Import Wiwimod</span></a>";
201
    } //else { echo "<B>&middot;</B>". 'wiwimod' ."";}
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% 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...
202
    $xwordsModule = $moduleHandler->getByDirname('xwords');
203
    $got_options  = false;
0 ignored issues
show
Unused Code introduced by
$got_options is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
204
    if (is_object($xwordsModule)) {
205
        $xwd_imgurl = XOOPS_URL . '/modules/xwords/images';
206
        ++$cf;
207
        echo "<a href=\"importxwords.php\"><img src=\"" . $xwd_imgurl . "/xwords_slogo.png\" alt=\"Xwords\" title=\"Xwords\" height=\"39\" width=\"69\"><span>Import Xwords</span></a>";
208
    }// else { echo "<B>&middot;</B>". 'xwords' ."";}
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% 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...
209
    echo '</div></td><tr></TABLE>';
210
}
211
212
/**
213
 * collapsable bar for items lists
214
 * @package       lexikon
215
 * @copyright (c) XOOPS Project (http://xoops.org)
216
 * @param string $tablename
217
 * @param string $iconname
218
 */
219
220
function lx_collapsableBar($tablename = '', $iconname = '')
221
{
222
    ?>
223
    <script type="text/javascript"><!--
224
        function goto_URL(object) {
225
            window.location.href = object.options[object.selectedIndex].value;
226
        }
227
228
        function toggle(id) {
229
            if (document.getElementById) {
230
                obj = document.getElementById(id);
231
            }
232
            if (document.all) {
233
                obj = document.all[id];
234
            }
235
            if (document.layers) {
236
                obj = document.layers[id];
237
            }
238
            if (obj) {
239
                if (obj.style.display == "none") {
240
                    obj.style.display = "";
241
                } else {
242
                    obj.style.display = "none";
243
                }
244
            }
245
246
            return false;
247
        }
248
249
        var iconClose = new Image();
250
        iconClose.src = '../assets/images/close12.gif';
251
        var iconOpen = new Image();
252
        iconOpen.src = '../assets/images/open12.gif';
253
254
        function toggleIcon(iconName) {
255
            if (document.images[iconName].src == window.iconOpen.src) {
256
                document.images[iconName].src = window.iconClose.src;
257
            }
258
            elseif(document.images[iconName].src == window.iconClose.src)
259
            {
260
                document.images[iconName].src = window.iconOpen.src;
261
            }
262
        }
263
264
        //-->
265
    </script>
266
    <?php
267
    // HTML Error Fixed by 5Vision
268
    echo "<div style=\"color: #2F5376; margin: 6px 0 0 0; \"><a href=\"#\" onClick=\"toggle('" . $tablename . "'); toggleIcon('" . $iconname . "');\">";
269
}
270
271
/**
272
 * Returns statistics about the Glossary
273
 * adapted from news module 1.0
274
 * @param $limit
275
 * @return array
276
 */
277
function lx_GetStatistics($limit)
278
{
279
    $ret  = array();
280
    $db   = XoopsDatabaseFactory::getDatabaseConnection();
281
    $tbls = $db->prefix('lxentries');
282
    $tblt = $db->prefix('lxcategories');
283
284
    $db = XoopsDatabaseFactory::getDatabaseConnection();
285
    // Number of Definitions per Category, including offline and submitted terms
286
    $ret2   = array();
287
    $sql    = "SELECT count(s.entryID) as cpt, s.categoryID, t.name FROM $tbls s, $tblt t WHERE s.categoryID=t.categoryID GROUP BY s.categoryID ORDER BY t.name";
288
    $result = $db->query($sql);
289
    while ($myrow = $db->fetchArray($result)) {
290
        $ret2[$myrow['categoryID']] = $myrow;
291
    }
292
    $ret['termspercategory'] = $ret2;
293
    unset($ret2);
294
295
    // Total reads per category
296
    $ret2   = array();
297
    $sql    = "SELECT Sum(counter) as cpt, categoryID FROM $tbls GROUP BY categoryID ORDER BY categoryID";
298
    $result = $db->query($sql);
299
    while ($myrow = $db->fetchArray($result)) {
300
        $ret2[$myrow['categoryID']] = $myrow['cpt'];
301
    }
302
    $ret['readspercategory'] = $ret2;
303
304
    // unused terms per category i.e. offline or submitted
305
    $ret2   = array();
306
    $sql    = "SELECT Count(entryID) as cpt, categoryID FROM $tbls WHERE offline > 0 OR submit > 0 GROUP BY categoryID ORDER BY categoryID";
307
    $result = $db->query($sql);
308
    while ($myrow = $db->fetchArray($result)) {
309
        $ret2[$myrow['categoryID']] = $myrow['cpt'];
310
    }
311
    $ret['offlinepercategory'] = $ret2;
312
    unset($ret2);
313
314
    // Number of unique authors per category
315
    $ret2   = array();
316
    $sql    = "SELECT Count(Distinct(uid)) as cpt, categoryID FROM $tbls GROUP BY categoryID ORDER BY categoryID";
317
    $result = $db->query($sql);
318
    while ($myrow = $db->fetchArray($result)) {
319
        $ret2[$myrow['categoryID']] = $myrow['cpt'];
320
    }
321
    $ret['authorspercategory'] = $ret2;
322
    unset($ret2);
323
324
    // Most read terms
325
    $ret2   = array();
326
    $sql    = "SELECT s.entryID, s.uid, s.term, s.counter, s.categoryID, t.name  FROM $tbls s, $tblt t WHERE s.categoryID=t.categoryID ORDER BY s.counter DESC";
327
    $result = $db->query($sql, (int)$limit);
328
    while ($myrow = $db->fetchArray($result)) {
329
        $ret2[$myrow['entryID']] = $myrow;
330
    }
331
    $ret['mostreadterms'] = $ret2;
332
    unset($ret2);
333
334
    // Less read terms
335
    $ret2   = array();
336
    $sql    = "SELECT s.entryID, s.uid, s.term, s.counter, s.categoryID, t.name  FROM $tbls s, $tblt t WHERE s.categoryID=t.categoryID ORDER BY s.counter";
337
    $result = $db->query($sql, (int)$limit);
338
    while ($myrow = $db->fetchArray($result)) {
339
        $ret2[$myrow['entryID']] = $myrow;
340
    }
341
    $ret['lessreadterms'] = $ret2;
342
    unset($ret2);
343
344
    // Most read authors
345
    $ret2   = array();
346
    $sql    = "SELECT Sum(counter) as cpt, uid FROM $tbls GROUP BY uid ORDER BY cpt DESC";
347
    $result = $db->query($sql, (int)$limit);
348
    while ($myrow = $db->fetchArray($result)) {
349
        $ret2[$myrow['uid']] = $myrow['cpt'];
350
    }
351
    $ret['mostreadauthors'] = $ret2;
352
    unset($ret2);
353
354
    // Biggest contributors
355
    $ret2   = array();
356
    $sql    = "SELECT Count(*) as cpt, uid FROM $tbls GROUP BY uid ORDER BY cpt DESC";
357
    $result = $db->query($sql, (int)$limit);
358
    while ($myrow = $db->fetchArray($result)) {
359
        $ret2[$myrow['uid']] = $myrow['cpt'];
360
    }
361
    $ret['biggestcontributors'] = $ret2;
362
    unset($ret2);
363
364
    return $ret;
365
}
366
367
//-- build a table header
368
function lx_buildTable()
369
{
370
    global $xoopsConfig, $xoopsModuleConfig, $xoopsModule;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
371
    echo "<div style='color: #2F5376; margin: 6px 0 0 0; '>";
372
    echo "<table width='100%' cellspacing='2' cellpadding='3' border='0' class='outer'>";
373
    //echo "<tr><td colspan='7' class='odd'>";
374
    //echo "<strong>". _AM_LEXIKON_INVENTORY . "</strong></td></tr>";
0 ignored issues
show
Unused Code Comprehensibility introduced by
37% 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...
375
    echo '<tr >';
376
    echo "<th width='40px'  align='center'><b>" . _AM_LEXIKON_ENTRYID . '</b></td>';
377
    echo "<th width='100px'  align='center'><b>" . _AM_LEXIKON_ENTRYCATNAME . '</b></td>';
378
    echo "<th align='center'><b>" . _AM_LEXIKON_TERM . '</b></td>';
379
    echo "<th width='90px'  align='center'><b>" . _AM_LEXIKON_AUTHOR . '</b></td>';
380
    echo "<th width='90px'  align='center'><b>" . _AM_LEXIKON_ENTRYCREATED . '</b></td>';
381
    echo "<th width='40px'  align='center'><b>" . _AM_LEXIKON_STATUS . '</b></td>';
382
    echo "<th width='60px'  align='center'><b>" . _AM_LEXIKON_ACTION . '</b></td>';
383
    echo '</tr>';
384
}
385
386
/**
387
 * save_permissions()
388
 * adapted from WF-Downloads
389
 * @param $groups
390
 * @param $id
391
 * @param $perm_name
392
 * @return bool
393
 */
394
395
function lx_save_Permissions($groups, $id, $perm_name)
396
{
397
    $result   = true;
398
    $hModule  = xoops_getHandler('module');
399
    $lxModule = $hModule->getByDirname('lexikon');
400
401
    $module_id     = $lxModule->getVar('mid');
402
    $gpermHandler = xoops_getHandler('groupperm');
403
404
    /*
405
    * First, if the permissions are already there, delete them
406
    */
407
    $gpermHandler->deleteByModule($module_id, $perm_name, $id);
408
    /*
409
    *  Save the new permissions
410
    */
411
    if (is_array($groups)) {
412
        foreach ($groups as $group_id) {
413
            $gpermHandler->addRight($perm_name, $id, $group_id, $module_id);
414
        }
415
    }
416
417
    return $result;
418
}
419
420
//-- Initial Selector
421
/**
422
 * @param $init
423
 */
424
function lx_getinit($init)
425
{
426
    global $init;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
427
    echo "<select name='init'>";
428
    echo "<option value='#'>&nbsp; # &nbsp;</option>";
429
    for ($a = 65; $a < (65 + 26); ++$a) {
430
        if (chr($a) == $init) {
431
            $opt_selected = 'selected';
432
        } else {
433
            $opt_selected = '';
434
        }
435
        echo "<option value='" . chr($a) . "' $opt_selected>&nbsp; " . chr($a) . ' &nbsp;</option>';
436
    }
437
    echo '</select></div>';
438
}
439