Completed
Push — master ( d327be...a5915e )
by Michael
04:34 queued 02:32
created

index.php (4 issues)

Labels
Severity

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
//             --  XoopsHP Module --       Xoops e-Learning System           //
4
//                     Copyright (c) 2005 SUDOW-SOKEN                        //
5
//                      <http://www.mailpark.co.jp/>                         //
6
//  ------------------------------------------------------------------------ //
7
//               Based on XoopsHP1.01 by Yoshi, aka HowardGee.               //
8
//  ------------------------------------------------------------------------ //
9
//  This program is free software; you can redistribute it and/or modify     //
10
//  it under the terms of the GNU General Public License as published by     //
11
//  the Free Software Foundation; either version 2 of the License, or        //
12
//  (at your option) any later version.                                      //
13
//                                                                           //
14
//  You may not change or alter any portion of this comment or credits       //
15
//  of supporting developers from this source code or any supporting         //
16
//  source code which is considered copyrighted (c) material of the          //
17
//  original comment or credit authors.                                      //
18
//                                                                           //
19
//  This program is distributed in the hope that it will be useful,          //
20
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
21
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
22
//  GNU General Public License for more details.                             //
23
//                                                                           //
24
//  You should have received a copy of the GNU General Public License        //
25
//  along with this program; if not, write to the Free Software              //
26
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
27
//  ------------------------------------------------------------------------ //
28
include __DIR__ . '/header.php';
29
30
// License check: Add access permission to the guest group if license hasn't been purchased
31
$groupperm_handler = xoops_getHandler('groupperm', 'xoopshp');
32
if (!$xoopsModuleConfig['has_license']
33
    && !$groupperm_handler->checkRight(
34
        'module_read',
35
        $xoopsModule->getVar('mid'),
36
        XOOPS_GROUP_ANONYMOUS
37
    )
38
) {
39
    //    $groupperm_handler->addRight('module_read', $xoopsModule->getVar('mid'), XOOPS_GROUP_ANONYMOUS);
40
    // Heck, can't figure out how to get around the restriction in the kernel, so here's a tentative workaround.
41
    $query  = 'INSERT INTO ' . $xoopsDB->prefix('group_permission')
42
              . ' (gperm_name, gperm_itemid, gperm_groupid, gperm_modid) VALUES (' . $xoopsDB->quoteString('module_read')
43
              . ', ' . $xoopsModule->getVar('mid') . ', ' . XOOPS_GROUP_ANONYMOUS . ', 1)';
44
    $result = $xoopsDB->queryF($query);
45
}
46
47
global $isModAdmin;
48
if ($xoopsUser && $xoopsUser->isAdmin($xoopsModule->mid())) {
49
    $isModAdmin = true;
50
} else {
51
    $isModAdmin = false;
52
}
53
54
function listsections()
55
{
56
    global $xoopsConfig, $xoopsModuleConfig, $xoopsDB, $xoopsUser, $xoopsTheme, $xoopsLogger, $xoopsModule, $xoopsTpl, $isModAdmin, $xoopsUserIsAdmin, $xoopsModuleConfig;
57
    include XOOPS_ROOT_PATH . '/header.php';
58
    $myts = MyTextSanitizer::getInstance();
59
    include __DIR__ . '/module_prefix.php';
60
    $result = $xoopsDB->query(
61
        'SELECT secid, secname, secdesc, display, expire FROM ' . $xoopsDB->prefix($module_prefix . '_sections')
0 ignored issues
show
The variable $module_prefix 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...
62
        . ' ORDER BY secname'
63
    );
64
    echo "<div style='text-align: center;'>";
65
    echo "<h2 align='center'>";
66
    printf($xoopsModuleConfig['welcome'], htmlspecialchars($xoopsConfig['sitename'], ENT_QUOTES));
67
    echo '</h2>';
68
    echo "<h4 align='center'>" . $xoopsModuleConfig['welcome_desc'] . '</h4>';
69
    echo "<div id='content'>";
70
    echo "<table border='0' cellspacing='1' cellpadding ='3' class='outer' width ='100%'><tr>";
71
    echo "<td align='left' valign='top'><b>" . _MD_RETURN2INDEX . '</b></td>';
72
    if ($xoopsUser) {
73
        echo
74
            "<td align='right' valign='center'><a href='index.php?op=portfolio&amp;secid=0&amp;sort_key=timestamp'><span style='font-weight:bold;font-size:larger;'>"
75
            . _MD_LT_PORTFOLIO . '</span></a></td>';
76
    }
77
    echo '</tr></table>';
78
79
    echo "<table border='0' cellspacing='1' cellpadding ='3' class='outer' width ='100%'>";
80
    echo '<tr>';
81
    echo '<th>' . _MD_SECNAMEC . '</th>';
82
    echo '<th>' . _MD_SECDESC . '</th>';
83
    echo '<th>' . _MD_SECQNUM . '</th>';
84
    if ($xoopsUser) {
85
        echo '<th>' . _MD_SECDNUM . '</th>';
86
    }
87
    echo '<th size=19>' . _MD_LT_EXPIRE . '</th>';
88
    echo '</tr>';
89
90
    while (list($secid, $secname, $secdesc, $display, $expire) = $xoopsDB->fetchRow($result)) {
91
        if ($display) {
92
            $secid       = (int)$secid;
93
            $secname     = $myts->stripSlashesGPC($secname);
94
            $secdesc     = $myts->stripSlashesGPC($secdesc);
95
            $expire      = $myts->stripSlashesGPC($expire);
96
            $currenttime = formatTimestamp(time(), 'Y-m-d H:i:s');
97
            echo '<tr>';
98
            if ($expire !== '0000-00-00 00:00:00' && $expire < $currenttime) {
99
                echo "<td class='even'>" . $myts->displayTarea($secname) . '</td>';
100
            } else {
101
                echo "<td class='even'><a href='index.php?op=listarticles&amp;secid=$secid'><b>$secname</b></a></td>";
102
            }
103
            echo "<td class='even'>" . $myts->displayTarea($secdesc) . '</td>';
104
            include __DIR__ . '/module_prefix.php';
105
            $result_db = $xoopsDB->prefix($module_prefix . '_results');
106
            include __DIR__ . '/module_prefix.php';
107
            $quiz_db = $xoopsDB->prefix($module_prefix . '_quiz');
108
            $qnum    = $xoopsDB->query("SELECT * FROM $quiz_db WHERE secid=$secid");
109
            $qnum    = $xoopsDB->getRowsNum($qnum);
110
            echo "<td class='even' align='center'>$qnum</td>";
111
            if ($xoopsUser) {
112
                include __DIR__ . '/module_prefix.php';
113
                $quiz_db = $xoopsDB->prefix($module_prefix . '_quiz');
114
                if ($isModAdmin) {
115
                    $query
116
                        = "SELECT DISTINCT $result_db.quiz_id, $quiz_db.artid, $quiz_db.secid FROM $result_db, $quiz_db WHERE $quiz_db.artid = $result_db.quiz_id AND $quiz_db.secid = $secid";
117
                } else {
118
                    $query = "SELECT DISTINCT $result_db.quiz_id, $quiz_db.artid, $quiz_db.secid FROM $result_db, $quiz_db WHERE $quiz_db.artid = $result_db.quiz_id AND $quiz_db.secid = $secid AND uid="
119
                        . $xoopsUser->getVar('uid');
120
                }
121
                $results = $xoopsDB->query($query);
122
                $done    = $xoopsDB->getRowsNum($results);
123
                echo "<td class='even' align='center'>$done</td>";
124
            }
125 View Code Duplication
            if ($expire !== '0000-00-00 00:00:00') {
126
                if ($expire > $currenttime) {
127
                    echo "<td class='even'>" . $expire . '</td>';
128
                } else {
129
                    echo "<td class='even'>" . $expire . "<span style='color:#ff0000;'>(" . _MD_LT_EXPIRED
130
                         . ')</span></td>';
131
                }
132
            } else {
133
                echo "<td class='even'>" . '-------------------' . '</td>';
134
            }
135
            echo '</tr>';
136
        }
137
    }
138
    echo '</table>';
139
140
    echo "<table border='0' cellspacing='1' cellpadding ='3' width ='100%'><tr>";
141
    echo "<td align='right'><a href='" . _MD_CREDITSITE . "' target='_credit'/ > Version " . round(
142
            $xoopsModule->getVar('version') / 100,
143
            2
144
        ) . '</a></td>';
145
    echo '</tr></table>';
146
    echo '</div>';
147
    echo '</div>';
148
    include dirname(dirname(__DIR__)) . '/footer.php';
149
}
150
151
/**
152
 * @param $secid
153
 */
154
function listarticles($secid)
155
{
156
    global $xoopsConfig, $xoopsModuleConfig, $xoopsUser, $xoopsDB, $xoopsTheme, $xoopsLogger, $xoopsModule, $xoopsTpl, $isModAdmin, $xoopsUserIsAdmin;
157
    include dirname(dirname(__DIR__)) . '/header.php';
158
    $myts  = MyTextSanitizer::getInstance();
159
    $secid = (int)$secid;
160
    include __DIR__ . '/module_prefix.php';
161
    $result = $xoopsDB->query(
162
        'SELECT secname, secdesc, display, expire FROM ' . $xoopsDB->prefix($module_prefix . '_sections') . " WHERE secid=$secid"
163
    );
164
    list($secname, $secdesc, $display, $expire) = $xoopsDB->fetchRow($result);
165
    $secname = $myts->displayTarea($myts->stripSlashesGPC($secname));
166
    $secdesc = $myts->displayTarea($myts->stripSlashesGPC($secdesc));
167
    $display = (int)$display;
168
    $expire  = $myts->displayTarea($myts->stripSlashesGPC($expire));
169
    // Trap for hidden or expired items
170
    if (!$display) {
171
        redirect_header('index.php', 2, _AM_MSG_ACCESS_ERROR);
172
    } elseif ($expire !== '0000-00-00 00:00:00' && $expire < formatTimestamp(time(), 'Y-m-d H:i:s')) {
173
        redirect_header('index.php', 2, _AM_MSG_ACCESS_ERROR);
174
    }
175
    include __DIR__ . '/module_prefix.php';
176
    $result = $xoopsDB->query(
177
        'SELECT artid, secid, title, posted, counter, display, expire FROM ' . $xoopsDB->prefix(
178
            $module_prefix . '_quiz'
179
        ) . " WHERE secid=$secid" . ' ORDER BY title'
180
    );
181
    echo "<div style='text-align: center;'>";
182
    echo "<h2 align='center'>$secname</h2>";
183
    echo "<h4 align='center'>" . _MD_THEFOLLOWING . '</h4>';
184
    echo "<div id='content'>";
185
    echo "<table border='0' cellspacing='1' cellpadding ='3' class='outer' width ='100%'><tr>";
186
    echo "<td align='left' valign='top'><b><a href=index.php>" . _MD_RETURN2INDEX . '</a> -> ' . _MD_RETURN2QUIZ
187
         . '</b></td>';
188
    if ($xoopsUser) {
189
        echo "<td align='right' valign='center'><a href='index.php?op=portfolio&amp;secid=$secid&amp;sort_key=timestamp'><span style='font-weight:bold;font-size:larger;'>"
190
            . _MD_LT_PORTFOLIO . '</span></a></td>';
191
        $alert = '';
192
    } else {
193
        $alert = " onClick='alert(\"" . _MD_ALERTGUEST . "\")'";
194
    }
195
    echo '</tr></table>';
196
    echo "<table border='0' cellspacing='1' cellpadding ='3' class='outer' width ='100%'>";
197
    echo '<tr>';
198
    echo '<th>' . _MD_LT_TITLE . '</th>';
199
    echo '<th>' . _XD_FB_FINISHED_BY . '</th>';
200
    if ($isModAdmin) {
201
        echo '<th>' . _MD_LT_SITEAVG . '</th>';
202
    } elseif ($xoopsUser) {
203
        echo '<th>' . _MD_LT_MYMAX . '</th>';
204
    }
205
    echo '<th>' . _MD_LT_SITEMAX . '</th>';
206
    echo '<th>' . _MD_LT_EXPIRE . '</th>';
207
    if ($xoopsUser) {
208
        echo '<th colspan=3>' . _MD_LT_ACTION . '</th>';
209
    }
210
    echo '</tr>';
211
    $currenttime = formatTimestamp(time(), 'Y-m-d H:i:s');
212
    while (list($artid, $secid, $title, $posted, $counter, $display, $expire) = $xoopsDB->fetchRow($result)) {
213
        if ($display) {
214
            $title  = $myts->displayTarea($title);
215
            $expire = $myts->stripSlashesGPC($expire);
216
            echo '<tr>';
217
            if ($expire !== '0000-00-00 00:00:00' && $expire < $currenttime) {
218
                echo "<td class='even'>$title</td>";
219
            } else {
220
                echo "<td class='even'><a href='index.php?op=viewarticle&amp;artid=$artid' target='quiz_window' $alert><b>$title</b></a></td>";
221
            }
222
            if ($xoopsUser) {
223
                $uid = $xoopsUser->getVar('uid');
224
                include __DIR__ . '/module_prefix.php';
225
                $query1 = 'SELECT DISTINCT uid FROM ' . $xoopsDB->prefix($module_prefix . '_results')
226
                          . " WHERE quiz_id=$artid";
227
                include __DIR__ . '/module_prefix.php';
228
                $query2 = 'SELECT score FROM ' . $xoopsDB->prefix($module_prefix . '_results')
229
                          . " WHERE quiz_id=$artid AND uid=$uid";
230
                if ($isModAdmin) {
231
                    $results_exist = $xoopsDB->query($query1);
232
                    $done_by       = $xoopsDB->query($query1);
233
                } else {
234
                    $results_exist = $xoopsDB->query($query2);
235
                    $done_by       = $xoopsDB->query($query1);
236
                }
237
                $results_exist = $xoopsDB->getRowsNum($results_exist);
238
            } else {
239
                include __DIR__ . '/module_prefix.php';
240
                $query1  = 'SELECT DISTINCT uid FROM ' . $xoopsDB->prefix($module_prefix . '_results')
241
                           . " WHERE quiz_id=$artid";
242
                $done_by = $xoopsDB->query($query1);
243
            }
244
            $done_by = $xoopsDB->getRowsNum($done_by);
245
            echo "<td class='even' align='center'>$done_by</td>";
246
            include __DIR__ . '/module_prefix.php';
247
            $site_max = $xoopsDB->query(
248
                'SELECT MAX(score), AVG(score) FROM ' . $xoopsDB->prefix($module_prefix . '_results') . " WHERE quiz_id = $artid"
249
            );
250
            list($site_max, $site_avg) = $xoopsDB->fetchRow($site_max);
251
            if ($isModAdmin) {
252
                echo "<td class='even' align='center'>" . round($site_avg) . '</td>';
253
            } elseif ($xoopsUser) {
254
                include __DIR__ . '/module_prefix.php';
255
                $my_max = $xoopsDB->query(
256
                    'SELECT MAX(score) FROM ' . $xoopsDB->prefix($module_prefix . '_results') . " WHERE uid = $uid AND quiz_id = $artid"
0 ignored issues
show
The variable $uid does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
257
                );
258
                list($my_max) = $xoopsDB->fetchRow($my_max);
259
                echo "<td class='even' align='center'>$my_max</td>";
260
            }
261
            echo "<td class='even' align='center'>$site_max</td>";
262 View Code Duplication
            if ($expire !== '0000-00-00 00:00:00') {
263
                if ($expire > $currenttime) {
264
                    echo "<td class='even'>" . $expire . '</td>';
265
                } else {
266
                    echo "<td class='even'>" . $expire . "<span style='color:#ff0000;'>(" . _MD_LT_EXPIRED
267
                         . ')</span></td>';
268
                }
269
            } else {
270
                echo "<td class='even'>" . '-------------------' . '</td>';
271
            }
272
            if ($xoopsUser) {
273
                if ($results_exist) {
274
                    echo "<td class='odd' align='center'><a href='index.php?op=viewresults&amp;artid=$artid&amp;sort_key=timestamp'>"
275
                        . _MD_LT_RESULTS . '</a></td>';
276
                } else {
277
                    echo "<td class='odd' align='center'>&nbsp;</td>";
278
                }
279
            }
280
            if ($isModAdmin) {
281
                echo "<td class='odd' align='center'><a href='admin/index.php?op=secartedit&amp;artid=$artid'>"
282
                    . _MD_EDIT . '</a></td>';
283
                echo "<td class='odd' align='center'><a href='admin/index.php?op=secartdelete&amp;artid=$artid'>"
284
                    . _MD_DELETE . '</a></td>';
285
            }
286
            echo '</tr>';
287
        }
288
    }
289
    echo '</table>';
290
    echo "<table border='0' cellspacing='1' cellpadding ='3' width ='100%'><tr>";
291
    echo "<td align='right'><a href='" . _MD_CREDITSITE . "' target='_credit'/ > Version " . round(
292
            $xoopsModule->getVar('version') / 100,
293
            2
294
        ) . '</a></td>';
295
    echo '</tr></table>';
296
    echo '</div>';
297
    echo '</div>';
298
    include dirname(dirname(__DIR__)) . '/footer.php';
299
}
300
301
/**
302
 * @param $artid
303
 */
304
function viewarticle($artid)
305
{
306
    global $xoopsConfig, $xoopsModuleConfig, $xoopsUser, $xoopsDB, $xoopsTpl, $isModAdmin, $xoopsUserIsAdmin;
307
    $myts  = MyTextSanitizer::getInstance();
308
    $artid = (int)$artid;
309
    include __DIR__ . '/module_prefix.php';
310
    $result = $xoopsDB->query(
311
        'SELECT secid, title, content, display, expire FROM ' . $xoopsDB->prefix($module_prefix . '_quiz') . " WHERE artid=$artid"
312
    );
313
    list($secid, $title, $content, $display, $expire) = $xoopsDB->fetchRow($result);
314
    $secid       = (int)$secid;
315
    $display     = (int)$display;
316
    $expire      = $myts->stripSlashesGPC($expire);
317
    $currenttime = formatTimestamp(time(), 'Y-m-d H:i:s');
318
    if ($display) {
319
        include __DIR__ . '/module_prefix.php';
320
        $result2 = $xoopsDB->query(
321
            'SELECT display, expire FROM ' . $xoopsDB->prefix($module_prefix . '_sections') . " WHERE secid=$secid"
322
        );
323
        list($display2, $expire2) = $xoopsDB->fetchRow($result2);
324
        $display2 = (int)$display2;
325
        $expire2  = $myts->stripSlashesGPC($expire2);
326
        if ($display2) {
327
            if ($expire2 === '0000-00-00 00:00:00' || $expire2 > $currenttime) {
328
                if ($expire === '0000-00-00 00:00:00' || $expire > $currenttime) {
329
                    setcookie('xoopsHP_file_id', $artid);
330
                    $title = $myts->displayTarea($title);
331
                    // Can't decide an appropriate sanitizer...
332
                    //$content = $myts->displayTarea($content, 1);
333
                    echo $content;
334
                } else {
335
                    redirect_header('index.php', 2, _AM_MSG_ACCESS_ERROR);
336
                }
337
            } else {
338
                redirect_header('index.php', 2, _AM_MSG_ACCESS_ERROR);
339
            }
340
        } else {
341
            redirect_header('index.php', 2, _AM_MSG_ACCESS_ERROR);
342
        }
343
    } else {
344
        redirect_header('index.php', 2, _AM_MSG_ACCESS_ERROR);
345
    }
346
}
347
348
/**
349
 * @param $artid
350
 * @param $sort_key
351
 */
352
function viewresults($artid, $sort_key)
353
{
354
    global $xoopsConfig, $xoopsModuleConfig, $xoopsUser, $xoopsDB, $xoopsTheme, $xoopsLogger, $xoopsModule, $xoopsTpl, $isModAdmin, $xoopsUserIsAdmin;
355
    include dirname(dirname(__DIR__)) . '/header.php';
356
    $myts = MyTextSanitizer::getInstance();
357
358
    //Retrieve table data by users
359
    $artid = (int)$artid;
360
    include __DIR__ . '/module_prefix.php';
361
    $result2 = $xoopsDB->query(
362
        'SELECT title, posted, secid FROM ' . $xoopsDB->prefix($module_prefix . '_quiz') . " WHERE artid=$artid"
0 ignored issues
show
The variable $module_prefix 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...
363
    );
364
    list($title, $posted, $secid) = $xoopsDB->fetchRow($result2);
365
    $title  = $myts->displayTarea($title);
366
    $posted = $myts->displayTarea($posted);
367
    include __DIR__ . '/module_prefix.php';
368
    $result_db = $xoopsDB->prefix($module_prefix . '_results');
369
    $users_db  = $xoopsDB->prefix('users');
370
    if ($isModAdmin) {
371
        $query = "SELECT $result_db.id, $result_db.quiz_id, $result_db.uid, $result_db.score, $result_db.timestamp, $result_db.comment, $users_db.uname, $users_db.name FROM $result_db, $users_db WHERE $result_db.uid = $users_db.uid AND $result_db.quiz_id = $artid ORDER BY "
372
            . $sort_key;
373 View Code Duplication
    } elseif ($xoopsUser) {
374
        $uid   = $xoopsUser->getVar('uid');
375
        $query = "SELECT $result_db.id, $result_db.quiz_id, $result_db.uid, $result_db.score, $result_db.timestamp,  $result_db.comment, $users_db.uname, $users_db.name FROM $result_db, $users_db WHERE $result_db.uid = $uid AND $result_db.uid = $users_db.uid AND $result_db.quiz_id = $artid ORDER BY "
376
            . $sort_key;
377
    }
378
    $result = $xoopsDB->query($query);
379
380
    echo "<div style='text-align: center;'>";
381
    echo "<h2 align='center'>" . _MD_LT_RESULTS
382
        . ": <a href='index.php?op=viewarticle&amp;artid=$artid' target='quiz_window'><span style='font-weight:bold;font-size:larger;'>$title</span></a></h2>";
383
    echo "<div id='content'>";
384
    echo "<table border='0' cellspacing='1' cellpadding ='3' class='outer' width ='100%'><tr>";
385
    echo "<td align='left' valign='top'><b><a href=index.php>" . _MD_RETURN2INDEX . "</a> -> <a href='index.php?op=listarticles&amp;secid=$secid'>"
386
        . _MD_RETURN2QUIZ . '</a> -> ' . _MD_RESULTLIST . ' (' . _MD_RESULT_SIMPLE . ') </b></td>';
387
    echo "<td align='right' valign='center'><a href='index.php?op=viewdetails&amp;artid=$artid&amp;sort_key=end_time'><span style='font-weight:bold;font-size:larger;'>"
388
        . _MD_RESULT_DETAIL . '</span></a></td>';
389
    echo '</tr></table>';
390
    echo "<table border='0' cellspacing='1' cellpadding ='3' class='outer' width ='100%'>";
391
    echo '<tr>';
392
    echo "<th><a href='index.php?op=viewresults&amp;artid=$artid&amp;sort_key=uname'>" . _MD_LT_STUDENT . '</a></th>';
393
    echo "<th><a href='index.php?op=viewresults&amp;artid=$artid&amp;sort_key=score'>" . _MD_LT_SCORE . '</a></th>';
394
    echo "<th><a href='index.php?op=viewresults&amp;artid=$artid&amp;sort_key=timestamp'>" . _MD_LT_DATE . '</a></th>';
395
    if ($isModAdmin) {
396
        echo "<th colspan=2 align='center'>" . _MD_LT_ACTION . '</th>';
397
    }
398
    echo '</tr>';
399
    while (list($res_id, $quiz_id, $uid, $score, $timestamp, $comment, $uname, $name) = $xoopsDB->fetchRow($result)) {
400
        echo '<tr>';
401 View Code Duplication
        if ($xoopsUser) {
402
            echo "<td class='even'>" . $uname;
403
            if (!empty($name)) {
404
                echo ' (' . $name . ')';
405
            }
406
            echo '</td>';
407
        }
408
        echo "<td class='even' align='center'>$score</td>";
409
        echo "<td class='even' align='center'>$timestamp</td>";
410
        if ($isModAdmin) {
411
            echo "<td class='odd' align='center'><a href='admin/index.php?op=resultdelete&amp;res_id=$res_id'>"
412
                . _MD_DELETE . '</a></td>';
413
        }
414
        echo '</tr>';
415
    }
416
    echo '</table>';
417
418
    echo "<table border='0' cellspacing='1' cellpadding ='3' width ='100%'><tr>";
419
    echo "<td align='right'><a href='" . _MD_CREDITSITE . "' target='_credit'/ > Version " . round(
420
            $xoopsModule->getVar('version') / 100,
421
            2
422
        ) . '</a></td>';
423
    echo '</tr></table>';
424
    echo '</div>';
425
    echo '</div>';
426
    include dirname(dirname(__DIR__)) . '/footer.php';
427
}
428
429
/**
430
 * @param $artid
431
 * @param $sort_key
432
 */
433
function viewdetails($artid, $sort_key)
434
{
435
    global $xoopsConfig, $xoopsModuleConfig, $xoopsUser, $xoopsDB, $xoopsTheme, $xoopsLogger, $xoopsModule, $xoopsTpl, $isModAdmin, $xoopsUserIsAdmin;
436
    include dirname(dirname(__DIR__)) . '/header.php';
437
    $myts     = MyTextSanitizer::getInstance();
438
    $artid    = (int)$artid;
439
    $sort_key = $myts->addSlashes($sort_key);
440
    //Retrieve table data by users
441
    include __DIR__ . '/module_prefix.php';
442
    $result2 = $xoopsDB->query(
443
        'SELECT title, posted, secid FROM ' . $xoopsDB->prefix($module_prefix . '_quiz') . " WHERE artid=$artid"
0 ignored issues
show
The variable $module_prefix 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...
444
    );
445
    list($title, $posted, $secid) = $xoopsDB->fetchRow($result2);
446
    $title  = $myts->displayTarea($title);
447
    $posted = $myts->displayTarea($posted);
448
    $uid    = $xoopsUser ? $xoopsUser->getVar('uid') : 0;
449
    include __DIR__ . '/module_prefix.php';
450
    $result_db = $xoopsDB->prefix($module_prefix . '_results');
451
    $users_db  = $xoopsDB->prefix('users');
452
    if ($isModAdmin) {
453
        $query = "SELECT $result_db.id, $result_db.quiz_id, $result_db.uid, $result_db.score, $result_db.start_time, $result_db.end_time, $result_db.timestamp, $result_db.host, $result_db.ip, $result_db.comment, $users_db.uname, $users_db.name FROM $result_db, $users_db WHERE $result_db.uid = $users_db.uid AND $result_db.quiz_id = $artid ORDER BY "
454
            . $sort_key;
455 View Code Duplication
    } elseif ($xoopsUser) {
456
        $query = "SELECT $result_db.id, $result_db.quiz_id, $result_db.uid, $result_db.score, $result_db.start_time, $result_db.end_time, $result_db.timestamp, $result_db.host, $result_db.ip, $result_db.comment, $users_db.uname, $users_db.name FROM $result_db, $users_db WHERE $result_db.uid = $uid AND $result_db.uid = $users_db.uid AND $result_db.quiz_id = $artid ORDER BY "
457
            . $sort_key;
458
    }
459
    $result = $xoopsDB->query($query);
460
461
    echo "<div style='text-align: center;'>";
462
    echo "<h2 align='center'>" . _MD_RESULT_DETAIL . ": <a href='index.php?op=viewarticle&amp;artid=$artid' target='quiz_window'><span style='font-weight:bold;font-size:larger;'>"
463
        . $title . '</span></a></h2>';
464
    echo "<div id='content'>";
465
    echo "<table border='0' cellspacing='1' cellpadding ='3' class='outer' width ='100%'><tr>";
466
    echo "<td align='left' valign='top'><b><a href=index.php>" . _MD_RETURN2INDEX . "</a> -> <a href='index.php?op=listarticles&amp;secid=$secid'>"
467
        . _MD_RETURN2QUIZ . '</a> -> ' . _MD_RESULTLIST . ' (' . _MD_RESULT_DETAIL . ') </b></td>';
468
    if ($xoopsUser) {
469
        echo "<td align='right' valign='center'><a href='index.php?op=viewresults&amp;artid=$artid&amp;sort_key=timestamp'><span style='font-weight:bold;font-size:larger;'>"
470
            . _MD_RESULT_SIMPLE . '</span></a></td>';
471
    }
472
    echo '</tr></table>';
473
474
    echo "<table border='0' cellspacing='1' cellpadding ='3' class='outer' width ='100%'>";
475
    echo '<tr>';
476
    echo "<th><a href='index.php?op=viewdetails&amp;artid=$artid&amp;sort_key=uname'>" . _MD_LT_STUDENT . '</a></th>';
477
    echo "<th><a href='index.php?op=viewdetails&amp;artid=$artid&amp;sort_key=score'>" . _MD_LT_SCORE . '</th>';
478
    echo
479
        "<th><a href='index.php?op=viewdetails&amp;artid=$artid&amp;sort_key=start_time'>" . _XD_FB_START . '</a></th>';
480
    echo "<th><a href='index.php?op=viewdetails&amp;artid=$artid&amp;sort_key=end_time'>" . _XD_FB_END . '</a></th>';
481
    echo "<th><a href='index.php?op=viewdetails&amp;artid=$artid&amp;sort_key=host'>" . _XD_FB_HOST . '</a></th>';
482
    echo "<th><a href='index.php?op=viewdetails&amp;artid=$artid&amp;sort_key=ip'>" . _XD_FB_IP . '</a></th>';
483
    if ($isModAdmin) {
484
        echo '<th>' . _MD_LT_ACTION . '</th>';
485
    }
486
    echo '</tr>';
487
    while (
488
    list($res_id, $quiz_id, $uid, $score, $start_time, $end_time, $timestamp, $host, $ip, $comment, $uname, $name)
489
        = $xoopsDB->fetchRow($result)) {
490
        echo '<tr>';
491 View Code Duplication
        if ($xoopsUser) {
492
            echo "<td nowrap class='even'>" . $uname;
493
            if (!empty($name)) {
494
                echo ' (' . $name . ')';
495
            }
496
            echo '</td>';
497
        }
498
        echo "<td class='even' align='center'>$score</td>";
499
        echo "<td class='even' align='center'>$start_time</td>";
500
        echo "<td class='even' align='center'>$end_time</td>";
501
        echo "<td class='even' align='center'>$host</td>";
502
        echo "<td class='even' align='center'>$ip</td>";
503
        if ($isModAdmin) {
504
            echo "<td class='odd' align='center' nowrap><a href='admin/index.php?op=resultdelete&amp;res_id=$res_id'>"
505
                . _MD_DELETE . '</td>';
506
        }
507
        echo '</tr>';
508
    }
509
510
    echo '</table>';
511
512
    echo "<table border='0' cellspacing='1' cellpadding ='3' width ='100%'><tr>";
513
    echo "<td align='right'><a href='" . _MD_CREDITSITE . "' target='_credit'/ > Version " . round(
514
            $xoopsModule->getVar('version') / 100,
515
            2
516
        ) . '</a></td>';
517
    echo '</tr></table>';
518
    echo '</div>';
519
    echo '</div>';
520
    include dirname(dirname(__DIR__)) . '/footer.php';
521
}
522
523
/**
524
 * @param $sort_key
525
 * @param $secid
526
 */
527
function portfolio($sort_key, $secid)
528
{
529
    global $xoopsConfig, $xoopsModuleConfig, $xoopsUser, $xoopsDB, $xoopsTheme, $xoopsLogger, $xoopsModule, $xoopsTpl, $isModAdmin, $xoopsUserIsAdmin;
530
    include dirname(dirname(__DIR__)) . '/header.php';
531
    $myts     = MyTextSanitizer::getInstance();
532
    $secid    = (int)$secid;
533
    $sort_key = $myts->addSlashes($sort_key);
534
    include __DIR__ . '/module_prefix.php';
535
    $result_db = $xoopsDB->prefix($module_prefix . '_results');
536
    include __DIR__ . '/module_prefix.php';
537
    $quiz_db  = $xoopsDB->prefix($module_prefix . '_quiz');
538
    $users_db = $xoopsDB->prefix('users');
539
    if ($secid == 0) {
540
        $section_query = '';
541
    } else {
542
        $section_query = "AND $quiz_db.secid = $secid ";
543
    }
544
    if ($isModAdmin) {
545
        $query     = "SELECT $result_db.id, $result_db.quiz_id, $result_db.uid, $result_db.score, $result_db.start_time, $result_db.end_time, $result_db.timestamp, $result_db.host, $result_db.ip, $result_db.comment, $quiz_db.artid, $quiz_db.secid, $quiz_db.title, $users_db.uid, $users_db.uname, $users_db.name FROM $result_db, $quiz_db, $users_db WHERE $quiz_db.artid = $result_db.quiz_id AND $result_db.uid = $users_db.uid "
546
            . $section_query . ' ORDER BY ' . $sort_key;
547
        $user_name = '';
548
    } elseif ($xoopsUser) {
549
        $user_id   = $xoopsUser->getVar('uid');
550
        $user_name = ' (' . $xoopsUser->getVar('uname') . ')';
551
        $query     = "SELECT $result_db.id, $result_db.quiz_id, $result_db.uid, $result_db.score, $result_db.start_time, $result_db.end_time, $result_db.timestamp, $result_db.host, $result_db.ip, $result_db.comment, $quiz_db.artid, $quiz_db.secid, $quiz_db.title, $users_db.uid, $users_db.uname, $users_db.name FROM $result_db, $quiz_db, $users_db WHERE $quiz_db.artid = $result_db.quiz_id AND $result_db.uid = $users_db.uid AND $result_db.uid=$user_id "
552
            . $section_query . ' ORDER BY ' . $sort_key;
553
    } else {
554
        $user_name = '';
555
    }
556
    $result = $xoopsDB->query($query);
557
558
    echo "<div style='text-align: center;'>";
559
    echo "<h2 align='center'>" . _MD_LT_PORTFOLIO . $user_name . '</h2>';
560
    echo "<div id='content'>";
561
    echo "<table border='0' cellspacing='1' cellpadding ='3' class='outer' width ='100%'>";
562
    echo "<form action='index.php?' method='get'><tr>";
563
    echo "<td align='left' valign='top'><b><a href=index.php>" . _MD_RETURN2INDEX . '</a> -> ' . _MD_LT_PORTFOLIO
564
         . '</td>';
565
    echo "<td align='right' valign='center'>" . _MD_SECNAMEC . "<input type='hidden' name='op' value='portfolio'>"
566
        . "<input type='hidden' name='sort_key' value='timestamp'>" . "<select name='secid'>";
567
568
    if ($secid == 0) {
569
        echo "<option value='0' selected>" . _MD_ALL . '</option>';
570
    } else {
571
        echo "<option value='0'>" . _MD_ALL . '</option>';
572
    }
573
    include __DIR__ . '/module_prefix.php';
574
    $courses = $xoopsDB->query(
575
        'SELECT secid, secname FROM ' . $xoopsDB->prefix($module_prefix . '_sections') . ' ORDER BY secname'
576
    );
577
    while (list($secid2list, $secname) = $xoopsDB->fetchRow($courses)) {
578
        $secname = $myts->displayTarea($secname);
579
        if ($secid2list == $secid) {
580
            echo "<option value='$secid2list' selected>$secname</option>";
581
        } else {
582
            echo "<option value='$secid2list'>$secname</option>";
583
        }
584
    }
585
586
    echo "</select><input type='submit' value='" . _MD_GO . "'></td>";
587
    echo '</tr></form></table>';
588
    echo "<table border='0' cellspacing='1' cellpadding ='3' class='outer' width ='100%'>";
589
    echo '<tr>';
590
    if ($isModAdmin) {
591
        echo "<th><a href='index.php?op=portfolio&amp;sort_key=uname'>" . _MD_LT_STUDENT . '</a></th>';
592
    }
593
    echo "<th><a href='index.php?op=portfolio&amp;sort_key=title'>" . _MD_LT_TITLE2 . '</a></th>';
594
    echo "<th><a href='index.php?op=portfolio&amp;sort_key=score'>" . _MD_LT_SCORE . '</a></th>';
595
    echo "<th><a href='index.php?op=portfolio&amp;sort_key=timestamp'>" . _MD_LT_DATE . '</a></th>';
596
    if ($isModAdmin) {
597
        echo "<th colspan=2 align='center'>" . _MD_LT_ACTION . '</th>';
598
    }
599
    echo '</tr>';
600
    while (
601
    list($res_id, $quiz_id, $uid, $score, $start_time, $end_time, $timestamp, $host, $ip, $comment, $artid, $secid,
602
        $title, $uid2, $uname, $name)
603
        = $xoopsDB->fetchRow($result)) {
604
        echo '<tr>';
605
        if ($isModAdmin) {
606
            echo "<td class='even'>" . $uname;
607
            if (!empty($name)) {
608
                echo ' (' . $name . ')';
609
            }
610
            echo '</td>';
611
        }
612
        echo "<td class='even'><a href='index.php?op=viewarticle&amp;artid=$artid' target='quiz_window'>$title</a></td>";
613
        echo "<td class='even' align='center'>$score</td>";
614
        echo "<td class='even' align='center'>$timestamp</td>";
615
        if ($isModAdmin) {
616
            echo "<td class='odd' align='center'><a href='admin/index.php?op=resultdelete&amp;res_id=$res_id'>"
617
                . _MD_DELETE . '</a></td>';
618
        }
619
        echo '</tr>';
620
    }
621
    echo '</table>';
622
623
    echo "<table border='0' cellspacing='1' cellpadding ='3' width ='100%'><tr>";
624
    echo "<td align='right'><a href='" . _MD_CREDITSITE . "' target='_credit'/ > Version " . round(
625
            $xoopsModule->getVar('version') / 100,
626
            2
627
        ) . '</a></td>';
628
    echo '</tr></table>';
629
    echo '</div>';
630
    echo '</div>';
631
    include dirname(dirname(__DIR__)) . '/footer.php';
632
}
633
634
$op = XoopsRequest::getString('op', '', 'GET');
635
$secid = XoopsRequest::getInt('secid', 0, 'GET');
636
$page = XoopsRequest::getInt('page', 0, 'GET');
637
$artid = XoopsRequest::getInt('artid', 0, 'GET');
638
$uid = XoopsRequest::getInt('uid', 0, 'GET');
639
$sort_key = XoopsRequest::getString('sort_key', 'uname', 'GET');
640
641
switch ($op) {
642
    case 'viewarticle':
643
        viewarticle($artid);
644
        break;
645
    case 'listarticles':
646
        listarticles($secid);
647
        break;
648
    case 'viewresults':
649
        viewresults($artid, $sort_key);
650
        break;
651
    case 'viewdetails':
652
        viewdetails($artid, $sort_key);
653
        break;
654
    case 'portfolio':
655
        portfolio($sort_key, $secid);
656
        break;
657
    default:
658
        listsections();
659
        break;
660
}
661