Utility   B
last analyzed

Complexity

Total Complexity 46

Size/Duplication

Total Lines 380
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 46
eloc 248
c 1
b 0
f 0
dl 0
loc 380
rs 8.72

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getBlockedHourlyStats() 0 41 5
C stats_adminmenu() 0 85 12
A getMonthlyStats() 0 40 3
C getMonth() 0 27 12
A getHourlyStats() 0 41 5
A getDailyStats() 0 39 3
A getBlockedMonthlyStats() 0 40 3
A getBlockedDailyStats() 0 39 3

How to fix   Complexity   

Complex Class

Complex classes like Utility often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Utility, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace XoopsModules\Statistics;
4
5
use XoopsModules\Statistics;
6
use XoopsModules\Statistics\Common;
7
use XoopsModules\Statistics\Constants;
8
9
/**
10
 * Class Utility
11
 */
12
class Utility extends Common\SysUtility
13
{
14
    //--------------- Custom module methods -----------------------------
15
16
public static function getMonthlyStats($year)
17
    {
18
        global $xoopsDB, $xoopsTpl;
19
20
        $now      = date('d-m-Y');
21
        $dot      = explode('-', $now);
22
        $nowmonth = $dot[1];
23
24
        $l_size = getimagesize('assets/images/leftbar.gif');
25
        $m_size = getimagesize('assets/images/mainbar.gif');
26
        $r_size = getimagesize('assets/images/rightbar.gif');
27
28
        // get monthly stats and display
29
        $resultmonth = $xoopsDB->queryF('select sum(hits) as totalhitsmonth from ' . $xoopsDB->prefix('stats_month') . " where year='$year'");
30
        [$totalhitsmonth] = $xoopsDB->fetchRow($resultmonth);
0 ignored issues
show
Comprehensibility Best Practice introduced by
This list assign is not used and could be removed.
Loading history...
31
        $xoopsDB->freeRecordSet($resultmonth);
32
        $result = $xoopsDB->queryF('select month,hits from ' . $xoopsDB->prefix('stats_month') . " where year='$year'");
33
        $xoopsTpl->assign('lang_stat_monthlystats', STATS_MONTHLYSTATS . '&nbsp;-&nbsp;' . $year);
34
        $xoopsTpl->assign('lang_stat_monthhead', STATS_MONTH);
35
        $resulttotal = $xoopsDB->queryF('select hits from ' . $xoopsDB->prefix('stats_year') . " where year='$year'");
36
        [$hitsforyear] = $xoopsDB->fetchRow($resulttotal);
37
        $monthlist = [];
38
        $i         = 0;
39
        while (list($month, $hits) = $xoopsDB->fetchRow($result)) {
40
            $monthlist[$i]['month'] = getMonth($month);
0 ignored issues
show
Bug introduced by
The function getMonth was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

40
            $monthlist[$i]['month'] = /** @scrutinizer ignore-call */ getMonth($month);
Loading history...
41
            $monthlist[$i]['hits']  = $hits;
42
            if ($month != $nowmonth) {
43
                $monthlist[$i]['link'] = "<a href=\"statdetails.php?op=monthlystats&year=$year&month=$month\">" . $monthlist[$i]['month'] . '</a>';
44
            } else {
45
                $monthlist[$i]['link'] = '';
46
            }
47
48
            $midbarsize               = mb_substr(100 * $hits / $hitsforyear, 0, 5);
49
            $monthlist[$i]['percent'] = $midbarsize . '%';
50
            $m_name                   = getMonth($month);
51
            $monthlist[$i]['graph']   = "<img src=\"assets/images/leftbar.gif\" height=\"$l_size[1]\" width=\"$l_size[0]\" Alt=\"$m_name - $hits\"><img src=\"assets/images/mainbar.gif\" Alt=\"$m_name - $hits\" height=\"$m_size[1]\" width=\"$midbarsize\"><img src=\"assets/images/rightbar.gif\" height=\"$r_size[1]\" width=\"$r_size[0]\" Alt=\"$m_name - $hits\">";
52
            ++$i;
53
        }
54
        $xoopsDB->freeRecordSet($result);
55
        $xoopsTpl->assign('monthlist', $monthlist);
56
    }
57
58
public static function getDailyStats($year, $month)
59
    {
60
        global $xoopsDB, $xoopsTpl;
61
62
        $now     = date('d-m-Y');
63
        $dot     = explode('-', $now);
64
        $nowdate = $dot[0];
65
66
        $l_size = getimagesize('assets/images/leftbar.gif');
67
        $m_size = getimagesize('assets/images/mainbar.gif');
68
        $r_size = getimagesize('assets/images/rightbar.gif');
69
70
        // get the daily stats and show
71
        $resulttotal = $xoopsDB->queryF('select sum(hits) as totalhitsdate from ' . $xoopsDB->prefix('stats_date') . " where year='$year' and month='$month'");
72
        [$totalhitsdate] = $xoopsDB->fetchRow($resulttotal);
73
        $xoopsDB->freeRecordSet($resulttotal);
74
        $result = $xoopsDB->queryF('select year,month,date,hits from ' . $xoopsDB->prefix('stats_date') . " where year='$year' and month='$month' order by date");
75
        $total  = $xoopsDB->getRowsNum($result);
0 ignored issues
show
Unused Code introduced by
The assignment to $total is dead and can be removed.
Loading history...
76
        $xoopsTpl->assign('lang_stat_dailystats', STATS_DAILYSTATS . '&nbsp;-&nbsp;' . getMonth($month) . '&nbsp;-&nbsp;' . $year);
0 ignored issues
show
Bug introduced by
The function getMonth was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

76
        $xoopsTpl->assign('lang_stat_dailystats', STATS_DAILYSTATS . '&nbsp;-&nbsp;' . /** @scrutinizer ignore-call */ getMonth($month) . '&nbsp;-&nbsp;' . $year);
Loading history...
77
        $xoopsTpl->assign('lang_stat_dailyhead', STATS_DAILY);
78
        $dailylist = [];
79
        $i         = 0;
80
        while (list($year, $month, $date, $hits) = $xoopsDB->fetchRow($result)) {
81
            $dailylist[$i]['year']  = $year;
82
            $dailylist[$i]['month'] = getMonth($month);
83
            $dailylist[$i]['date']  = $date;
84
            $dailylist[$i]['hits']  = $hits;
85
            if ($date != $nowdate) {
86
                $dailylist[$i]['link'] = "<a href=\"statdetails.php?op=dailystats&year=$year&month=$month&date=$date\">" . $date . '</a>';
87
            } else {
88
                $dailylist[$i]['link'] = '';
89
            }
90
            $midbarsize               = mb_substr(100 * $hits / $totalhitsdate, 0, 5);
91
            $dailylist[$i]['percent'] = $midbarsize . '%';
92
            $dailylist[$i]['graph']   = "<img src=\"assets/images/leftbar.gif\" height=\"$l_size[1]\" width=\"$l_size[0]\" Alt=\"$date - $hits\"><img src=\"assets/images/mainbar.gif\" Alt=\"$date - $hits\" height=\"$m_size[1]\" width=\"$midbarsize\"><img src=\"assets/images/rightbar.gif\" height=\"$r_size[1]\" width=\"$r_size[0]\" Alt=\"$date - $hits\">";
93
            ++$i;
94
        }
95
        $xoopsDB->freeRecordSet($result);
96
        $xoopsTpl->assign('dailylist', $dailylist);
97
    }
98
99
public static function getHourlyStats($year, $month, $date)
100
    {
101
        global $xoopsDB, $xoopsTpl;
102
103
        $l_size = getimagesize('assets/images/leftbar.gif');
104
        $m_size = getimagesize('assets/images/mainbar.gif');
105
        $r_size = getimagesize('assets/images/rightbar.gif');
106
107
        $now = date('d-m-Y');
108
109
        // show hourly stats and display
110
        $resulttotal = $xoopsDB->queryF('select sum(hits) as totalhitshour from ' . $xoopsDB->prefix('stats_hour') . " where year='$year' and month='$month' and date='$date'");
111
        [$totalhitshour] = $xoopsDB->fetchRow($resulttotal);
112
        $xoopsDB->freeRecordSet($resulttotal);
113
        $date_arr = explode('-', $now);
0 ignored issues
show
Unused Code introduced by
The assignment to $date_arr is dead and can be removed.
Loading history...
114
        $xoopsTpl->assign('lang_stat_hourlystats', STATS_HOURLYSTATS . '&nbsp;-&nbsp;' . getMonth($month) . '&nbsp;' . $date . '&nbsp;' . $year);
0 ignored issues
show
Bug introduced by
The function getMonth was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

114
        $xoopsTpl->assign('lang_stat_hourlystats', STATS_HOURLYSTATS . '&nbsp;-&nbsp;' . /** @scrutinizer ignore-call */ getMonth($month) . '&nbsp;' . $date . '&nbsp;' . $year);
Loading history...
115
        $xoopsTpl->assign('lang_stat_hourlyhead', STATS_HOURLY);
116
        $hourlist = [];
117
118
        for ($k = 0; $k <= 23; ++$k) {
119
            $result = $xoopsDB->queryF('select hour,hits from ' . $xoopsDB->prefix('stats_hour') . " where year='$year' and month='$month' and date='$date' and hour='$k'");
120
            if (0 == $xoopsDB->getRowsNum($result)) {
121
                $hits = 0;
122
                $hour = $k;
123
            } else {
124
                [$hour, $hits] = $xoopsDB->fetchRow($result);
125
            }
126
127
            $a                    = (($k < 10) ? "0$k" : $k);
128
            $hourlist[$k]['hour'] = "$a:00 - $a:59";
129
130
            $a = '';
0 ignored issues
show
Unused Code introduced by
The assignment to $a is dead and can be removed.
Loading history...
131
132
            $midbarsize              = ((0 == $hits) ? 0 : mb_substr(100 * $hits / $totalhitshour, 0, 5));
133
            $hourlist[$k]['hits']    = $hits;
134
            $hourlist[$k]['percent'] = $midbarsize . '%';
135
            $hourlist[$k]['graph']   = "<img src=\"assets/images/leftbar.gif\" height=\"$l_size[1]\" width=\"$l_size[0]\" Alt=\"$hour - $hits\"><img src=\"assets/images/mainbar.gif\" Alt=\"$hour - $hits\" height=\"$m_size[1]\" width=\"$midbarsize\"><img src=\"assets/images/rightbar.gif\" height=\"$r_size[1]\" width=\"$r_size[0]\" Alt=\"$hour - $hits\">";
136
        }
137
138
        $xoopsDB->freeRecordSet($result);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $result does not seem to be defined for all execution paths leading up to this point.
Loading history...
139
        $xoopsTpl->assign('hourlist', $hourlist);
140
    }
141
142
public static function getBlockedMonthlyStats($year)
143
    {
144
        global $xoopsDB, $xoopsTpl;
145
146
        $now      = date('d-m-Y');
147
        $dot      = explode('-', $now);
148
        $nowmonth = $dot[1];
149
150
        $l_size = getimagesize('assets/images/leftbar.gif');
151
        $m_size = getimagesize('assets/images/mainbar.gif');
152
        $r_size = getimagesize('assets/images/rightbar.gif');
153
154
        // get monthly stats and display
155
        $resultmonth = $xoopsDB->queryF('select sum(hits) as totalhitsmonth from ' . $xoopsDB->prefix('stats_blockedmonth') . " where year='$year'");
156
        [$totalhitsmonth] = $xoopsDB->fetchRow($resultmonth);
0 ignored issues
show
Comprehensibility Best Practice introduced by
This list assign is not used and could be removed.
Loading history...
157
        $xoopsDB->freeRecordSet($resultmonth);
158
        $result = $xoopsDB->queryF('select month,hits from ' . $xoopsDB->prefix('stats_blockedmonth') . " where year='$year'");
159
        $xoopsTpl->assign('lang_stat_monthlystats', STATS_BLOCKEDMONTHLYSTATS . '&nbsp;-&nbsp;' . $year);
160
        $xoopsTpl->assign('lang_stat_monthhead', STATS_MONTH);
161
        $resulttotal = $xoopsDB->queryF('select hits from ' . $xoopsDB->prefix('stats_blockedyear') . " where year='$year'");
162
        [$hitsforyear] = $xoopsDB->fetchRow($resulttotal);
163
        $monthlist = [];
164
        $i         = 0;
165
        while (list($month, $hits) = $xoopsDB->fetchRow($result)) {
166
            $monthlist[$i]['month'] = getMonth($month);
0 ignored issues
show
Bug introduced by
The function getMonth was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

166
            $monthlist[$i]['month'] = /** @scrutinizer ignore-call */ getMonth($month);
Loading history...
167
            $monthlist[$i]['hits']  = $hits;
168
            if ($month != $nowmonth) {
169
                $monthlist[$i]['link'] = "<a href=\"statdetails.php?op=b_monthlystats&year=$year&month=$month\">" . $monthlist[$i]['month'] . '</a>';
170
            } else {
171
                $monthlist[$i]['link'] = '';
172
            }
173
174
            $midbarsize               = mb_substr(100 * $hits / $hitsforyear, 0, 5);
175
            $monthlist[$i]['percent'] = $midbarsize . '%';
176
            $m_name                   = getMonth($month);
177
            $monthlist[$i]['graph']   = "<img src=\"assets/images/leftbar.gif\" height=\"$l_size[1]\" width=\"$l_size[0]\" Alt=\"$m_name - $hits\"><img src=\"assets/images/mainbar.gif\" Alt=\"$m_name - $hits\" height=\"$m_size[1]\" width=\"$midbarsize\"><img src=\"assets/images/rightbar.gif\" height=\"$r_size[1]\" width=\"$r_size[0]\" Alt=\"$m_name - $hits\">";
178
            ++$i;
179
        }
180
        $xoopsDB->freeRecordSet($result);
181
        $xoopsTpl->assign('monthlist', $monthlist);
182
    }
183
184
public static function getBlockedDailyStats($year, $month)
185
    {
186
        global $xoopsDB, $xoopsTpl;
187
188
        $now     = date('d-m-Y');
189
        $dot     = explode('-', $now);
190
        $nowdate = $dot[0];
191
192
        $l_size = getimagesize('assets/images/leftbar.gif');
193
        $m_size = getimagesize('assets/images/mainbar.gif');
194
        $r_size = getimagesize('assets/images/rightbar.gif');
195
196
        // get the daily stats and show
197
        $resulttotal = $xoopsDB->queryF('select sum(hits) as totalhitsdate from ' . $xoopsDB->prefix('stats_blockeddate') . " where year='$year' and month='$month'");
198
        [$totalhitsdate] = $xoopsDB->fetchRow($resulttotal);
199
        $xoopsDB->freeRecordSet($resulttotal);
200
        $result = $xoopsDB->queryF('select year,month,date,hits from ' . $xoopsDB->prefix('stats_blockeddate') . " where year='$year' and month='$month' order by date");
201
        $total  = $xoopsDB->getRowsNum($result);
0 ignored issues
show
Unused Code introduced by
The assignment to $total is dead and can be removed.
Loading history...
202
        $xoopsTpl->assign('lang_stat_dailystats', STATS_BLOCKEDDAILYSTATS . '&nbsp;-&nbsp;' . getMonth($month) . '&nbsp;-&nbsp;' . $year);
0 ignored issues
show
Bug introduced by
The function getMonth was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

202
        $xoopsTpl->assign('lang_stat_dailystats', STATS_BLOCKEDDAILYSTATS . '&nbsp;-&nbsp;' . /** @scrutinizer ignore-call */ getMonth($month) . '&nbsp;-&nbsp;' . $year);
Loading history...
203
        $xoopsTpl->assign('lang_stat_dailyhead', STATS_DAILY);
204
        $dailylist = [];
205
        $i         = 0;
206
        while (list($year, $month, $date, $hits) = $xoopsDB->fetchRow($result)) {
207
            $dailylist[$i]['year']  = $year;
208
            $dailylist[$i]['month'] = getMonth($month);
209
            $dailylist[$i]['date']  = $date;
210
            $dailylist[$i]['hits']  = $hits;
211
            if ($date != $nowdate) {
212
                $dailylist[$i]['link'] = "<a href=\"statdetails.php?op=b_dailystats&year=$year&month=$month&date=$date\">" . $date . '</a>';
213
            } else {
214
                $dailylist[$i]['link'] = '';
215
            }
216
            $midbarsize               = mb_substr(100 * $hits / $totalhitsdate, 0, 5);
217
            $dailylist[$i]['percent'] = $midbarsize . '%';
218
            $dailylist[$i]['graph']   = "<img src=\"assets/images/leftbar.gif\" height=\"$l_size[1]\" width=\"$l_size[0]\" Alt=\"$date - $hits\"><img src=\"assets/images/mainbar.gif\" Alt=\"$date - $hits\" height=\"$m_size[1]\" width=\"$midbarsize\"><img src=\"assets/images/rightbar.gif\" height=\"$r_size[1]\" width=\"$r_size[0]\" Alt=\"$date - $hits\">";
219
            ++$i;
220
        }
221
        $xoopsDB->freeRecordSet($result);
222
        $xoopsTpl->assign('dailylist', $dailylist);
223
    }
224
225
public static function getBlockedHourlyStats($year, $month, $date)
226
    {
227
        global $xoopsDB, $xoopsTpl;
228
229
        $l_size = getimagesize('assets/images/leftbar.gif');
230
        $m_size = getimagesize('assets/images/mainbar.gif');
231
        $r_size = getimagesize('assets/images/rightbar.gif');
232
233
        $now = date('d-m-Y');
234
235
        // show hourly stats and display
236
        $resulttotal = $xoopsDB->queryF('select sum(hits) as totalhitshour from ' . $xoopsDB->prefix('stats_blockedhour') . " where year='$year' and month='$month' and date='$date'");
237
        [$totalhitshour] = $xoopsDB->fetchRow($resulttotal);
238
        $xoopsDB->freeRecordSet($resulttotal);
239
        $date_arr = explode('-', $now);
0 ignored issues
show
Unused Code introduced by
The assignment to $date_arr is dead and can be removed.
Loading history...
240
        $xoopsTpl->assign('lang_stat_hourlystats', STATS_BLOCKEDHOURLYSTATS . '&nbsp;-&nbsp;' . getMonth($month) . '&nbsp;' . $date . '&nbsp;' . $year);
0 ignored issues
show
Bug introduced by
The function getMonth was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

240
        $xoopsTpl->assign('lang_stat_hourlystats', STATS_BLOCKEDHOURLYSTATS . '&nbsp;-&nbsp;' . /** @scrutinizer ignore-call */ getMonth($month) . '&nbsp;' . $date . '&nbsp;' . $year);
Loading history...
241
        $xoopsTpl->assign('lang_stat_hourlyhead', STATS_HOURLY);
242
        $hourlist = [];
243
244
        for ($k = 0; $k <= 23; ++$k) {
245
            $result = $xoopsDB->queryF('select hour,hits from ' . $xoopsDB->prefix('stats_blockedhour') . " where year='$year' and month='$month' and date='$date' and hour='$k'");
246
            if (0 == $xoopsDB->getRowsNum($result)) {
247
                $hits = 0;
248
                $hour = $k;
249
            } else {
250
                [$hour, $hits] = $xoopsDB->fetchRow($result);
251
            }
252
253
            $a                    = (($k < 10) ? "0$k" : $k);
254
            $hourlist[$k]['hour'] = "$a:00 - $a:59";
255
256
            $a = '';
0 ignored issues
show
Unused Code introduced by
The assignment to $a is dead and can be removed.
Loading history...
257
258
            $midbarsize              = ((0 == $hits) ? 0 : mb_substr(100 * $hits / $totalhitshour, 0, 5));
259
            $hourlist[$k]['hits']    = $hits;
260
            $hourlist[$k]['percent'] = $midbarsize . '%';
261
            $hourlist[$k]['graph']   = "<img src=\"assets/images/leftbar.gif\" height=\"$l_size[1]\" width=\"$l_size[0]\" Alt=\"$hour - $hits\"><img src=\"assets/images/mainbar.gif\" Alt=\"$hour - $hits\" height=\"$m_size[1]\" width=\"$midbarsize\"><img src=\"assets/images/rightbar.gif\" height=\"$r_size[1]\" width=\"$r_size[0]\" Alt=\"$hour - $hits\">";
262
        }
263
264
        $xoopsDB->freeRecordSet($result);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $result does not seem to be defined for all execution paths leading up to this point.
Loading history...
265
        $xoopsTpl->assign('hourlist', $hourlist);
266
    }
267
268
public static function getMonth($month)
269
    {
270
        switch ($month) {
271
            case 1:
272
                return STATS_JANUARY;
273
            case 2:
274
                return STATS_FEBRUARY;
275
            case 3:
276
                return STATS_MARCH;
277
            case 4:
278
                return STATS_APRIL;
279
            case 5:
280
                return STATS_MAY;
281
            case 6:
282
                return STATS_JUNE;
283
            case 7:
284
                return STATS_JULY;
285
            case 8:
286
                return STATS_AUGUST;
287
            case 9:
288
                return STATS_SEPTEMBER;
289
            case 10:
290
                return STATS_OCTOBER;
291
            case 11:
292
                return STATS_NOVEMBER;
293
            default:
294
                return STATS_DECEMBER;
295
        }
296
    }
297
298
    /**
299
     * adminmenu()
300
     *
301
     * @param string       $header optional : You can gice the menu a nice header
302
     * @param string       $extra  optional : You can gice the menu a nice footer
303
     * @param array|string $menu   required : This is an array of links. U can
304
     * @param int          $scount required : This will difine the amount of cells long the menu will have.
305
     *                             NB: using a value of 3 at the moment will break the menu where the cell colours will be off display.
306
     */
307
public static function stats_adminmenu($header = '', $extra = '', $menu = '', $scount = 4)
308
    {
309
        global $xoopsConfig, $xoopsModule;
310
311
        if (empty($menu)) {
312
            /**
313
             * You can change this part to suit your own module. Defining this here will save you form having to do this each time.
314
             */
315
316
            $menu = [
317
                STATS_ADMENU1  => XOOPS_URL . '/modules/system/admin.php?fct=preferences&amp;op=showmod&amp;mod=' . $xoopsModule->getVar('mid'),
318
                STATS_ADMENU2  => 'index.php?op=' . INFO_GENERAL,
319
                STATS_ADMENU3  => 'index.php?op=' . INFO_CREDITS,
320
                STATS_ADMENU4  => 'index.php?op=' . INFO_CONFIGURATION,
321
                STATS_ADMENU5  => 'index.php?op=' . INFO_MODULES,
322
                STATS_ADMENU6  => 'index.php?op=' . INFO_ENVIRONMENT,
323
                STATS_ADMENU7  => 'index.php?op=' . INFO_VARIABLES,
324
                STATS_ADMENU8  => 'index.php?op=' . INFO_LICENSE,
325
                STATS_ADMENU9  => 'index.php?op=' . INFO_ALL,
326
                STATS_ADMENU10 => 'index.php?op=remote_addr',
327
                STATS_ADMENU11 => 'index.php?op=refer',
328
                STATS_ADMENU12 => 'index.php?op=userscreen',
329
            ];
330
        }
331
332
        $oddnum = [1 => '1', 3 => '3', 5 => '5', 7 => '7', 9 => '9', 11 => '11', 13 => '13'];
333
334
        /**
335
         * the amount of cells per menu row
336
         */
337
        $count = 0;
338
        /**
339
         * Set up the first class
340
         */
341
        $class = 'even';
342
        /**
343
         * Sets up the width of each menu cell
344
         */
345
346
        echo '<h3>' . $header . '</h3>';
347
        echo "<table width = '100%' cellpadding= '2' cellspacing= '1' class='outer'><tr>";
348
349
        /**
350
         * Check to see if $menu is and array
351
         */
352
        if (is_array($menu)) {
353
            foreach ($menu as $menutitle => $menulink) {
354
                ++$count;
355
                $width = 100 / $scount;
356
                $width = round($width);
357
                /**
358
                 * Menu table begin
359
                 */
360
                echo "<td class='$class' align='center' valign='middle' width= $width%>";
361
                echo "<a href='" . $menulink . "'>" . $menutitle . '</a></td>';
362
363
                /**
364
                 * Break menu cells to start a new row if $count > $scount
365
                 */
366
                if ($count >= $scount) {
367
                    /**
368
                     * If $class is the same for the end and start cells, invert $class
369
                     */
370
                    $class = ('odd' === $class && in_array($count, $oddnum)) ? 'even' : 'odd';
371
                    echo '</tr>';
372
                    $count = 0;
373
                } else {
374
                    $class = ('even' === $class) ? 'odd' : 'even';
375
                }
376
            }
377
            /**
378
             * checks to see if there are enough cell to fill menu row, if not add empty cells
379
             */
380
            if ($count >= 1) {
381
                $counter = 0;
382
                while ($counter < $scount - $count) {
383
                    echo '<td class="' . $class . '">&nbsp;</td>';
384
                    $class = ('even' === $class) ? 'odd' : 'even';
385
                    ++$counter;
386
                }
387
            }
388
            echo '</table><br>';
389
        }
390
        if ($extra) {
391
            echo "<div>$extra</div>";
392
        }
393
    }
394
395
}
396