Completed
Push — master ( ded118...cf7347 )
by Michael
02:48
created

functions.php ➔ lx_GetStatistics()   F

Complexity

Conditions 9
Paths 256

Size

Total Lines 88
Code Lines 62

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 9
eloc 62
c 1
b 0
f 0
nc 256
nop 1
dl 0
loc 88
rs 3.4768

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
 * $Id: functions.php v 1.0 18 Dec 2011 Yerres Exp $
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
        exit();
16
    }
17
} else {
18
    redirect_header(XOOPS_URL."/",1,_NOPERM);
19
    exit();
20
}
21
/**
22
 * Function used to display an horizontal menu inside the admin panel
23
 * Enable webmasters to navigate thru the module's features.
24
 * Each time you select an option in the admin panel of the news module, this option is highlighted in this menu
25
 * @package lexikon
26
 * @orig author: hsalazar, The smartfactory
27
 * @copyright	(c) The Xoops Project - www.xoops.org
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 '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.html' );
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
*/
67
function lx_FieldExists($fieldname, $table) {
68
    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...
69
    $result=$xoopsDB->queryF("SHOW COLUMNS FROM	$table LIKE '$fieldname'");
70
71
    return($xoopsDB->getRowsNum($result) > 0);
72
}
73
74
/**
75
 * Add a field to a mysql table
76
 *
77
 * @package Lexikon
78
 * @author Instant Zero (http://xoops.instant-zero.com)
79
 * @copyright (c) Instant Zero
80
 */
81
82
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...
83
    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...
84
    //naja !
85
    $result=$xoopsDB->queryF("ALTER TABLE " . $table . " ADD ".$field."");
86
87
    return $result;
88
}
89
/**
90
 * Change a field to a mysql table
91
 * desuet
92
 * @package Lexikon
93
 * @author Instant Zero (http://xoops.instant-zero.com)
94
 * @copyright (c) Instant Zero
95
 */
96
97
function lx_alterTable($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...
98
    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...
99
    $sql = "SHOW COLUMNS FROM ".$table." LIKE '".$field."'";
100
    $result = $xoopsDB->queryF($sql);
101
    //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...
102
    if ($xoopsDB->getRowsNum($result) == 0) {
103
        $sql = "ALTER TABLE ".$xoopsDB->prefix($table)." ADD `".$field."`";
104
105
        return $xoopsDB->query($sql);
106
        //   }
107
    }
108
109
    return true;
110
}
111
112
/*
113
 * Sub-Menu for Importscripts
114
 * @package lexikon
115
 * @copyright (c) The Xoops Project - www.xoops.org
116
*/
117
118
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...
119
    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...
120
    echo "<style type=\"text/css\">
121
    br {clear: left;}
122
    img {border:0;}
123
    #menu {width:400px; position:relative;  height:80px; margin:1em auto auto 2em;}
124
    #menu a:visited, #menu a {text-decoration:none; color:#d00; font-weight:bold;}
125
    #menu a:visited img, #menu a img{filter: alpha(opacity=40);
126
    filter: progid:DXImageTransform.Microsoft.Alpha(opacity=40);
127
    -moz-opacity: 0.40; opacity:0.4;
128
}
129
    #menu a:hover {background-color:trans; color:#06a;}
130
    #menu a span {display:none;}
131
    #menu a:hover span {display:block; position:absolute; top:50px; left:0; font-size:12px; height:18px; padding:4px; font-weight:normal; color:#a40;}
132
133
    #menu a:hover img { filter: alpha(opacity=100);
134
    filter: progid:DXImageTransform.Microsoft.Alpha(opacity=100);
135
    -moz-opacity: 1.00; opacity:1;
136
}
137
    </style>";
138
    echo " <TABLE BORDER=0 CELLPADDING=1 CELLSPACING=2 width='98%'>
139
    <TR><TD width='200' VALIGN='top'>
140
    <h3>Import Menu</h3><FONT SIZE='1'>";
141
    if ($cf < 5) {
142
        echo ""._AM_LEXIKON_OTHERMODS."";
143
    } else {
144
        echo ""._AM_LEXIKON_NOOTHERMODS."";
145
    }
146
147
    echo "</FONT></TD><TD VALIGN='top'>
148
    <div id=\"menu\">";
149
    // show only modules located on the system
150
    $module_handler = xoops_gethandler('module');
151
    $wordbookModule = $module_handler->getByDirname("wordbook");
152
    $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...
153
    $cf=0;
154
    if (is_object($wordbookModule)) {
155
        $wb_imgurl = XOOPS_URL.'/modules/wordbook/images';
156
        $cf++;
157
        echo "<a href=\"importwordbook.php\">
158
        <img src=\"".$wb_imgurl."/wb_slogo.png\" alt=\"wb_slogo.png\" title=\"Wordbook\" height=\"39\" width=\"69\"><span>Import Wordbook</span></a>";
159
    } //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...
160
    $dictionaryModule = $module_handler->getByDirname("dictionary");
161
    $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...
162
    if (is_object($dictionaryModule)) {
163
        $dic_imgurl = XOOPS_URL.'/modules/dictionary/images';
164
        $cf++;
165
        echo "<a href=\"importdictionary.php\">
166
        <img src=\"".$dic_imgurl."/dictionary_logo.png\" alt=\"Dictionary\" title=\"Dictionary\" height=\"39\" width=\"69\"><span>Import Dictionary</span></a>";
167
    } //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...
168
    $glossaireModule = $module_handler->getByDirname("glossaire");
169
    $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...
170
    if (is_object($glossaireModule)) {
171
        $glo_imgurl = XOOPS_URL.'/modules/glossaire.';
172
        $cf++;
173
        echo "<a href=\"importglossaire.php\">
174
        <img src=\"".$glo_imgurl."/glossaire_logo.jpg\" alt=\"Glossaire\" title=\"Glossaire\" height=\"31\" width=\"88\"><span>Import Glossaire</span></a>";
175
    } //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...
176
    $wiwimodModule = $module_handler->getByDirname("wiwimod");
177
    $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...
178
    if (is_object($wiwimodModule)) {
179
        $wiwi_imgurl = XOOPS_URL.'/modules/wiwimod/images';
180
        $cf++;
181
        echo "<a href=\"importwiwimod.php\"><img src=\"".$wiwi_imgurl."/wiwilogo.gif\" alt=\"Wiwimod\" title=\"Wiwimod\" height=\"39\" width=\"69\"><span>Import Wiwimod</span></a>";
182
    } //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...
183
    $xwordsModule = $module_handler->getByDirname("xwords");
184
    $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...
185
    if (is_object($xwordsModule)) {
186
        $xwd_imgurl = XOOPS_URL.'/modules/xwords/images';
187
        $cf++;
188
        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>";
189
    }// 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...
190
    echo "</div></TD><TR></TABLE>";
191
192
}
193
194
/**
195
 * collapsable bar for items lists
196
 * @package lexikon
197
 * @copyright (c) The Xoops Project - www.xoops.org
198
 */
199
200
function lx_collapsableBar($tablename = '', $iconname = '') {
201
202
    ?>
203
    <script type="text/javascript"><!--
204
                 function goto_URL(object) {
205
                     window.location.href = object.options[object.selectedIndex].value;
206
                 }
207
208
                 function toggle(id) {
209
                     if (document.getElementById) {
210
                         obj = document.getElementById(id);
211
                     }
212
                     if (document.all) {
213
                         obj = document.all[id];
214
                     }
215
                     if (document.layers) {
216
                         obj = document.layers[id];
217
                     }
218
                     if (obj) {
219
                         if (obj.style.display == "none") {
220
                             obj.style.display = "";
221
                         } else {
222
                             obj.style.display = "none";
223
                         }
224
                     }
225
                     return false;
226
                 }
227
228
                 var iconClose = new Image();
229
    iconClose.src = '../images/close12.gif';
230
    var iconOpen = new Image();
231
    iconOpen.src = '../images/open12.gif';
232
233
    function toggleIcon ( iconName ) {
234
        if ( document.images[iconName].src == window.iconOpen.src ) {
235
            document.images[iconName].src = window.iconClose.src;
236
        } else if ( document.images[iconName].src == window.iconClose.src ) {
237
            document.images[iconName].src = window.iconOpen.src;
238
        }
239
        return;
240
    }
241
242
    //-->
243
    </script>
244
    <?php
245
    // HTML Error Fixed by 5Vision
246
    echo "<div style=\"color: #2F5376; margin: 6px 0 0 0; \"><a href=\"#\" onClick=\"toggle('" . $tablename . "'); toggleIcon('" . $iconname . "');\">";
247
}
248
249
/**
250
 * Returns statistics about the Glossary
251
 * adapted from news module 1.0
252
 */
253
function lx_GetStatistics($limit){
254
    $ret=array();
255
    $db =& XoopsDatabaseFactory::getDatabaseConnection();
256
    $tbls=$db->prefix('lxentries');
257
    $tblt=$db->prefix('lxcategories');
258
259
    $db =& XoopsDatabaseFactory::getDatabaseConnection();
260
    // Number of Definitions per Category, including offline and submitted terms
261
    $ret2=array();
262
    $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";
263
    $result = $db->query($sql);
264
    while ($myrow = $db->fetchArray($result) ) {
265
        $ret2[$myrow['categoryID']]=$myrow;
266
    }
267
    $ret['termspercategory']=$ret2;
268
    unset($ret2);
269
270
    // Total reads per category
271
    $ret2=array();
272
    $sql="SELECT Sum(counter) as cpt, categoryID FROM $tbls GROUP BY categoryID ORDER BY categoryID";
273
    $result = $db->query($sql);
274
    while ($myrow = $db->fetchArray($result) ) {
275
        $ret2[$myrow['categoryID']]=$myrow['cpt'];
276
    }
277
    $ret['readspercategory']=$ret2;
278
279
    // unused terms per category i.e. offline or submitted
280
    $ret2=array();
281
    $sql="SELECT Count(entryID) as cpt, categoryID FROM $tbls WHERE offline > 0 OR submit > 0 GROUP BY categoryID ORDER BY categoryID";
282
    $result = $db->query($sql);
283
    while ($myrow = $db->fetchArray($result) ) {
284
        $ret2[$myrow['categoryID']]=$myrow['cpt'];
285
    }
286
    $ret['offlinepercategory']=$ret2;
287
    unset($ret2);
288
289
    // Number of unique authors per category
290
    $ret2=array();
291
    $sql="SELECT Count(Distinct(uid)) as cpt, categoryID FROM $tbls GROUP BY categoryID ORDER BY categoryID";
292
    $result = $db->query($sql);
293
    while ($myrow = $db->fetchArray($result) ) {
294
        $ret2[$myrow['categoryID']]=$myrow['cpt'];
295
    }
296
    $ret['authorspercategory']=$ret2;
297
    unset($ret2);
298
299
    // Most read terms
300
    $ret2=array();
301
    $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";
302
    $result = $db->query($sql,intval($limit));
303
    while ($myrow = $db->fetchArray($result) ) {
304
        $ret2[$myrow['entryID']]=$myrow;
305
    }
306
    $ret['mostreadterms']=$ret2;
307
    unset($ret2);
308
309
    // Less read terms
310
    $ret2=array();
311
    $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";
312
    $result = $db->query($sql,intval($limit));
313
    while ($myrow = $db->fetchArray($result) ) {
314
        $ret2[$myrow['entryID']]=$myrow;
315
    }
316
    $ret['lessreadterms']=$ret2;
317
    unset($ret2);
318
319
    // Most read authors
320
    $ret2=array();
321
    $sql="SELECT Sum(counter) as cpt, uid FROM $tbls GROUP BY uid ORDER BY cpt DESC";
322
    $result = $db->query($sql,intval($limit));
323
    while ($myrow = $db->fetchArray($result) ) {
324
        $ret2[$myrow['uid']]=$myrow['cpt'];
325
    }
326
    $ret['mostreadauthors']=$ret2;
327
    unset($ret2);
328
329
    // Biggest contributors
330
    $ret2=array();
331
    $sql="SELECT Count(*) as cpt, uid FROM $tbls GROUP BY uid ORDER BY cpt DESC";
332
    $result = $db->query($sql,intval($limit));
333
    while ($myrow = $db->fetchArray($result) ) {
334
        $ret2[$myrow['uid']]=$myrow['cpt'];
335
    }
336
    $ret['biggestcontributors']=$ret2;
337
    unset($ret2);
338
339
    return $ret;
340
}
341
342
//-- build a table header
343
function lx_buildTable(){
344
    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...
345
    echo "<div style='color: #2F5376; margin: 6px 0 0 0; '>";
346
    echo "<table width='100%' cellspacing='2' cellpadding='3' border='0' class='outer'>";
347
    //echo "<tr><td colspan='7' class='odd'>";
348
    //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...
349
    echo "<tr >";
350
    echo "<th width='40px'  align='center'><b>" . _AM_LEXIKON_ENTRYID . "</b></td>";
351
    echo "<th width='100px'  align='center'><b>" . _AM_LEXIKON_ENTRYCATNAME . "</b></td>";
352
    echo "<th align='center'><b>" . _AM_LEXIKON_TERM . "</b></td>";
353
    echo "<th width='90px'  align='center'><b>" . _AM_LEXIKON_AUTHOR . "</b></td>";
354
    echo "<th width='90px'  align='center'><b>" . _AM_LEXIKON_ENTRYCREATED . "</b></td>";
355
    echo "<th width='40px'  align='center'><b>" . _AM_LEXIKON_STATUS . "</b></td>";
356
    echo "<th width='60px'  align='center'><b>" . _AM_LEXIKON_ACTION . "</b></td>";
357
    echo "</tr>";
358
}
359
360
/**
361
 * save_permissions()
362
 * adapted from WF-Downloads
363
 */
364
365
function lx_save_Permissions($groups, $id, $perm_name) {
366
    $result = true;
367
    $hModule = & xoops_gethandler('module');
368
    $lxModule = & $hModule -> getByDirname('lexikon');
369
370
    $module_id = $lxModule -> getVar('mid');
371
    $gperm_handler = & xoops_gethandler('groupperm');
372
373
    /*
374
    * First, if the permissions are already there, delete them
375
    */
376
    $gperm_handler -> deleteByModule($module_id, $perm_name, $id);
377
    /*
378
    *  Save the new permissions
379
    */
380
    if (is_array($groups)){
381
        foreach ($groups as $group_id){
382
            $gperm_handler -> addRight($perm_name, $id, $group_id, $module_id);
383
        }
384
    }
385
386
    return $result;
387
}
388
389
//-- Initial Selector
390
function lx_getinit($init) {
391
    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...
392
    echo "<select name='init'>";
393
    echo "<option value='#'>&nbsp; # &nbsp;</option>";
394
    for ($a = 65; $a < (65+26); $a++ ) {
395
        if ( chr($a) == $init) {
396
            $opt_selected = "selected='selected'";
397
        } else {
398
            $opt_selected = "";
399
        }
400
        echo "<option value='".chr($a)."' $opt_selected>&nbsp; ".chr($a)." &nbsp;</option>";
401
    }
402
    echo "</select></div>";
403
}
404
?>
405