Issues (102)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

index.php (3 issues)

Upgrade to new PHP Analysis Engine

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

1
<?php
2
//  ------------------------------------------------------------------------ //
3
//             --  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('module_read', $xoopsModule->getVar('mid'), XOOPS_GROUP_ANONYMOUS)
34
) {
35
    //    $groupperm_handler->addRight('module_read', $xoopsModule->getVar('mid'), XOOPS_GROUP_ANONYMOUS);
0 ignored issues
show
Unused Code Comprehensibility introduced by
69% 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...
36
    // Heck, can't figure out how to get around the restriction in the kernel, so here's a tentative workaround.
37
    $query  = 'INSERT INTO ' . $xoopsDB->prefix('group_permission') . ' (gperm_name, gperm_itemid, gperm_groupid, gperm_modid) VALUES (' . $xoopsDB->quoteString('module_read') . ', '
38
              . $xoopsModule->getVar('mid') . ', ' . XOOPS_GROUP_ANONYMOUS . ', 1)';
39
    $result = $xoopsDB->queryF($query);
40
}
41
42
global $isModAdmin;
43
if ($xoopsUser && $xoopsUser->isAdmin($xoopsModule->mid())) {
44
    $isModAdmin = true;
45
} else {
46
    $isModAdmin = false;
47
}
48
49
function listsections()
50
{
51
    global $xoopsConfig, $xoopsModuleConfig, $xoopsDB, $xoopsUser, $xoopsTheme, $xoopsLogger, $xoopsModule, $xoopsTpl, $isModAdmin, $xoopsUserIsAdmin, $xoopsModuleConfig;
52
    include XOOPS_ROOT_PATH . '/header.php';
53
    $myts = MyTextSanitizer::getInstance();
54
    include __DIR__ . '/module_prefix.php';
55
    $result = $xoopsDB->query('SELECT secid, secname, secdesc, display, expire FROM ' . $xoopsDB->prefix($module_prefix . '_sections') . ' ORDER BY secname');
56
    echo "<div style='text-align: center;'>";
57
    echo "<h2 align='center'>";
58
    printf($xoopsModuleConfig['welcome'], htmlspecialchars($xoopsConfig['sitename'], ENT_QUOTES));
59
    echo '</h2>';
60
    echo "<h4 align='center'>" . $xoopsModuleConfig['welcome_desc'] . '</h4>';
61
    echo "<div id='content'>";
62
    echo "<table border='0' cellspacing='1' cellpadding ='3' class='outer' width ='100%'><tr>";
63
    echo "<td align='left' valign='top'><b>" . _MD_RETURN2INDEX . '</b></td>';
64
    if ($xoopsUser) {
65
        echo "<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;'>" . _MD_LT_PORTFOLIO
66
             . '</span></a></td>';
67
    }
68
    echo '</tr></table>';
69
70
    echo "<table border='0' cellspacing='1' cellpadding ='3' class='outer' width ='100%'>";
71
    echo '<tr>';
72
    echo '<th>' . _MD_SECNAMEC . '</th>';
73
    echo '<th>' . _MD_SECDESC . '</th>';
74
    echo '<th>' . _MD_SECQNUM . '</th>';
75
    if ($xoopsUser) {
76
        echo '<th>' . _MD_SECDNUM . '</th>';
77
    }
78
    echo '<th size=19>' . _MD_LT_EXPIRE . '</th>';
79
    echo '</tr>';
80
81
    while (list($secid, $secname, $secdesc, $display, $expire) = $xoopsDB->fetchRow($result)) {
82
        if ($display) {
83
            $secid       = (int)$secid;
84
            $secname     = $myts->stripSlashesGPC($secname);
85
            $secdesc     = $myts->stripSlashesGPC($secdesc);
86
            $expire      = $myts->stripSlashesGPC($expire);
87
            $currenttime = formatTimestamp(time(), 'Y-m-d H:i:s');
88
            echo '<tr>';
89
            if ($expire !== '0000-00-00 00:00:00' && $expire < $currenttime) {
90
                echo "<td class='even'>" . $myts->displayTarea($secname) . '</td>';
91
            } else {
92
                echo "<td class='even'><a href='index.php?op=listarticles&amp;secid=$secid'><b>$secname</b></a></td>";
93
            }
94
            echo "<td class='even'>" . $myts->displayTarea($secdesc) . '</td>';
95
            include __DIR__ . '/module_prefix.php';
96
            $result_db = $xoopsDB->prefix($module_prefix . '_results');
97
            include __DIR__ . '/module_prefix.php';
98
            $quiz_db = $xoopsDB->prefix($module_prefix . '_quiz');
99
            $qnum    = $xoopsDB->query("SELECT * FROM $quiz_db WHERE secid=$secid");
100
            $qnum    = $xoopsDB->getRowsNum($qnum);
101
            echo "<td class='even' align='center'>$qnum</td>";
102
            if ($xoopsUser) {
103
                include __DIR__ . '/module_prefix.php';
104
                $quiz_db = $xoopsDB->prefix($module_prefix . '_quiz');
105
                if ($isModAdmin) {
106
                    $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";
107
                } else {
108
                    $query =
109
                        "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="
110
                        . $xoopsUser->getVar('uid');
111
                }
112
                $results = $xoopsDB->query($query);
113
                $done    = $xoopsDB->getRowsNum($results);
114
                echo "<td class='even' align='center'>$done</td>";
115
            }
116 View Code Duplication
            if ($expire !== '0000-00-00 00:00:00') {
117
                if ($expire > $currenttime) {
118
                    echo "<td class='even'>" . $expire . '</td>';
119
                } else {
120
                    echo "<td class='even'>" . $expire . "<span style='color:#ff0000;'>(" . _MD_LT_EXPIRED . ')</span></td>';
121
                }
122
            } else {
123
                echo "<td class='even'>" . '-------------------' . '</td>';
124
            }
125
            echo '</tr>';
126
        }
127
    }
128
    echo '</table>';
129
130
    echo "<table border='0' cellspacing='1' cellpadding ='3' width ='100%'><tr>";
131
    echo "<td align='right'><a href='" . _MD_CREDITSITE . "' target='_credit'/ > Version " . round($xoopsModule->getVar('version') / 100, 2) . '</a></td>';
132
    echo '</tr></table>';
133
    echo '</div>';
134
    echo '</div>';
135
    include dirname(dirname(__DIR__)) . '/footer.php';
136
}
137
138
/**
139
 * @param $secid
140
 */
141
function listarticles($secid)
142
{
143
    global $xoopsConfig, $xoopsModuleConfig, $xoopsUser, $xoopsDB, $xoopsTheme, $xoopsLogger, $xoopsModule, $xoopsTpl, $isModAdmin, $xoopsUserIsAdmin;
144
    include dirname(dirname(__DIR__)) . '/header.php';
145
    $myts  = MyTextSanitizer::getInstance();
146
    $secid = (int)$secid;
147
    include __DIR__ . '/module_prefix.php';
148
    $result = $xoopsDB->query('SELECT secname, secdesc, display, expire FROM ' . $xoopsDB->prefix($module_prefix . '_sections') . " WHERE secid=$secid");
149
    list($secname, $secdesc, $display, $expire) = $xoopsDB->fetchRow($result);
150
    $secname = $myts->displayTarea($myts->stripSlashesGPC($secname));
151
    $secdesc = $myts->displayTarea($myts->stripSlashesGPC($secdesc));
152
    $display = (int)$display;
153
    $expire  = $myts->displayTarea($myts->stripSlashesGPC($expire));
154
    // Trap for hidden or expired items
155
    if (!$display) {
156
        redirect_header('index.php', 2, _AM_MSG_ACCESS_ERROR);
157
    } elseif ($expire !== '0000-00-00 00:00:00' && $expire < formatTimestamp(time(), 'Y-m-d H:i:s')) {
158
        redirect_header('index.php', 2, _AM_MSG_ACCESS_ERROR);
159
    }
160
    include __DIR__ . '/module_prefix.php';
161
    $result = $xoopsDB->query('SELECT artid, secid, title, posted, counter, display, expire FROM ' . $xoopsDB->prefix($module_prefix . '_quiz') . " WHERE secid=$secid" . ' ORDER BY title');
162
    echo "<div style='text-align: center;'>";
163
    echo "<h2 align='center'>$secname</h2>";
164
    echo "<h4 align='center'>" . _MD_THEFOLLOWING . '</h4>';
165
    echo "<div id='content'>";
166
    echo "<table border='0' cellspacing='1' cellpadding ='3' class='outer' width ='100%'><tr>";
167
    echo "<td align='left' valign='top'><b><a href=index.php>" . _MD_RETURN2INDEX . '</a> -> ' . _MD_RETURN2QUIZ . '</b></td>';
168
    if ($xoopsUser) {
169
        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;'>" . _MD_LT_PORTFOLIO
170
             . '</span></a></td>';
171
        $alert = '';
172
    } else {
173
        $alert = " onClick='alert(\"" . _MD_ALERTGUEST . "\")'";
174
    }
175
    echo '</tr></table>';
176
    echo "<table border='0' cellspacing='1' cellpadding ='3' class='outer' width ='100%'>";
177
    echo '<tr>';
178
    echo '<th>' . _MD_LT_TITLE . '</th>';
179
    echo '<th>' . _XD_FB_FINISHED_BY . '</th>';
180
    if ($isModAdmin) {
181
        echo '<th>' . _MD_LT_SITEAVG . '</th>';
182
    } elseif ($xoopsUser) {
183
        echo '<th>' . _MD_LT_MYMAX . '</th>';
184
    }
185
    echo '<th>' . _MD_LT_SITEMAX . '</th>';
186
    echo '<th>' . _MD_LT_EXPIRE . '</th>';
187
    if ($xoopsUser) {
188
        echo '<th colspan=3>' . _MD_LT_ACTION . '</th>';
189
    }
190
    echo '</tr>';
191
    $currenttime = formatTimestamp(time(), 'Y-m-d H:i:s');
192
    while (list($artid, $secid, $title, $posted, $counter, $display, $expire) = $xoopsDB->fetchRow($result)) {
193
        if ($display) {
194
            $title  = $myts->displayTarea($title);
195
            $expire = $myts->stripSlashesGPC($expire);
196
            echo '<tr>';
197
            if ($expire !== '0000-00-00 00:00:00' && $expire < $currenttime) {
198
                echo "<td class='even'>$title</td>";
199
            } else {
200
                echo "<td class='even'><a href='index.php?op=viewarticle&amp;artid=$artid' target='quiz_window' $alert><b>$title</b></a></td>";
201
            }
202
            if ($xoopsUser) {
203
                $uid = $xoopsUser->getVar('uid');
204
                include __DIR__ . '/module_prefix.php';
205
                $query1 = 'SELECT DISTINCT uid FROM ' . $xoopsDB->prefix($module_prefix . '_results') . " WHERE quiz_id=$artid";
206
                include __DIR__ . '/module_prefix.php';
207
                $query2 = 'SELECT score FROM ' . $xoopsDB->prefix($module_prefix . '_results') . " WHERE quiz_id=$artid AND uid=$uid";
208
                if ($isModAdmin) {
209
                    $results_exist = $xoopsDB->query($query1);
210
                    $done_by       = $xoopsDB->query($query1);
211
                } else {
212
                    $results_exist = $xoopsDB->query($query2);
213
                    $done_by       = $xoopsDB->query($query1);
214
                }
215
                $results_exist = $xoopsDB->getRowsNum($results_exist);
216
            } else {
217
                include __DIR__ . '/module_prefix.php';
218
                $query1  = 'SELECT DISTINCT uid FROM ' . $xoopsDB->prefix($module_prefix . '_results') . " WHERE quiz_id=$artid";
219
                $done_by = $xoopsDB->query($query1);
220
            }
221
            $done_by = $xoopsDB->getRowsNum($done_by);
222
            echo "<td class='even' align='center'>$done_by</td>";
223
            include __DIR__ . '/module_prefix.php';
224
            $site_max = $xoopsDB->query('SELECT MAX(score), AVG(score) FROM ' . $xoopsDB->prefix($module_prefix . '_results') . " WHERE quiz_id = $artid");
225
            list($site_max, $site_avg) = $xoopsDB->fetchRow($site_max);
226
            if ($isModAdmin) {
227
                echo "<td class='even' align='center'>" . round($site_avg) . '</td>';
228
            } elseif ($xoopsUser) {
229
                include __DIR__ . '/module_prefix.php';
230
                $my_max = $xoopsDB->query('SELECT MAX(score) FROM ' . $xoopsDB->prefix($module_prefix . '_results') . " WHERE uid = $uid AND quiz_id = $artid");
231
                list($my_max) = $xoopsDB->fetchRow($my_max);
232
                echo "<td class='even' align='center'>$my_max</td>";
233
            }
234
            echo "<td class='even' align='center'>$site_max</td>";
235 View Code Duplication
            if ($expire !== '0000-00-00 00:00:00') {
236
                if ($expire > $currenttime) {
237
                    echo "<td class='even'>" . $expire . '</td>';
238
                } else {
239
                    echo "<td class='even'>" . $expire . "<span style='color:#ff0000;'>(" . _MD_LT_EXPIRED . ')</span></td>';
240
                }
241
            } else {
242
                echo "<td class='even'>" . '-------------------' . '</td>';
243
            }
244
            if ($xoopsUser) {
245
                if ($results_exist) {
246
                    echo "<td class='odd' align='center'><a href='index.php?op=viewresults&amp;artid=$artid&amp;sort_key=timestamp'>" . _MD_LT_RESULTS . '</a></td>';
247
                } else {
248
                    echo "<td class='odd' align='center'>&nbsp;</td>";
249
                }
250
            }
251
            if ($isModAdmin) {
252
                echo "<td class='odd' align='center'><a href='admin/index.php?op=secartedit&amp;artid=$artid'>" . _MD_EDIT . '</a></td>';
253
                echo "<td class='odd' align='center'><a href='admin/index.php?op=secartdelete&amp;artid=$artid'>" . _MD_DELETE . '</a></td>';
254
            }
255
            echo '</tr>';
256
        }
257
    }
258
    echo '</table>';
259
    echo "<table border='0' cellspacing='1' cellpadding ='3' width ='100%'><tr>";
260
    echo "<td align='right'><a href='" . _MD_CREDITSITE . "' target='_credit'/ > Version " . round($xoopsModule->getVar('version') / 100, 2) . '</a></td>';
261
    echo '</tr></table>';
262
    echo '</div>';
263
    echo '</div>';
264
    include dirname(dirname(__DIR__)) . '/footer.php';
265
}
266
267
/**
268
 * @param $artid
269
 */
270
function viewarticle($artid)
271
{
272
    global $xoopsConfig, $xoopsModuleConfig, $xoopsUser, $xoopsDB, $xoopsTpl, $isModAdmin, $xoopsUserIsAdmin;
273
    $myts  = MyTextSanitizer::getInstance();
274
    $artid = (int)$artid;
275
    include __DIR__ . '/module_prefix.php';
276
    $result = $xoopsDB->query('SELECT secid, title, content, display, expire FROM ' . $xoopsDB->prefix($module_prefix . '_quiz') . " WHERE artid=$artid");
277
    list($secid, $title, $content, $display, $expire) = $xoopsDB->fetchRow($result);
278
    $secid       = (int)$secid;
279
    $display     = (int)$display;
280
    $expire      = $myts->stripSlashesGPC($expire);
281
    $currenttime = formatTimestamp(time(), 'Y-m-d H:i:s');
282
    if ($display) {
283
        include __DIR__ . '/module_prefix.php';
284
        $result2 = $xoopsDB->query('SELECT display, expire FROM ' . $xoopsDB->prefix($module_prefix . '_sections') . " WHERE secid=$secid");
285
        list($display2, $expire2) = $xoopsDB->fetchRow($result2);
286
        $display2 = (int)$display2;
287
        $expire2  = $myts->stripSlashesGPC($expire2);
288
        if ($display2) {
289
            if ($expire2 === '0000-00-00 00:00:00' || $expire2 > $currenttime) {
290
                if ($expire === '0000-00-00 00:00:00' || $expire > $currenttime) {
291
                    setcookie('xoopsHP_file_id', $artid);
292
                    $title = $myts->displayTarea($title);
0 ignored issues
show
$title 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...
293
                    // Can't decide an appropriate sanitizer...
294
                    //$content = $myts->displayTarea($content, 1);
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% 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...
295
                    echo $content;
296
                } else {
297
                    redirect_header('index.php', 2, _AM_MSG_ACCESS_ERROR);
298
                }
299
            } else {
300
                redirect_header('index.php', 2, _AM_MSG_ACCESS_ERROR);
301
            }
302
        } else {
303
            redirect_header('index.php', 2, _AM_MSG_ACCESS_ERROR);
304
        }
305
    } else {
306
        redirect_header('index.php', 2, _AM_MSG_ACCESS_ERROR);
307
    }
308
}
309
310
/**
311
 * @param $artid
312
 * @param $sort_key
313
 */
314
function viewresults($artid, $sort_key)
315
{
316
    global $xoopsConfig, $xoopsModuleConfig, $xoopsUser, $xoopsDB, $xoopsTheme, $xoopsLogger, $xoopsModule, $xoopsTpl, $isModAdmin, $xoopsUserIsAdmin;
317
    include dirname(dirname(__DIR__)) . '/header.php';
318
    $myts = MyTextSanitizer::getInstance();
319
320
    //Retrieve table data by users
321
    $artid = (int)$artid;
322
    include __DIR__ . '/module_prefix.php';
323
    $result2 = $xoopsDB->query('SELECT title, posted, secid FROM ' . $xoopsDB->prefix($module_prefix . '_quiz') . " WHERE artid=$artid");
324
    list($title, $posted, $secid) = $xoopsDB->fetchRow($result2);
325
    $title  = $myts->displayTarea($title);
326
    $posted = $myts->displayTarea($posted);
327
    include __DIR__ . '/module_prefix.php';
328
    $result_db = $xoopsDB->prefix($module_prefix . '_results');
329
    $users_db  = $xoopsDB->prefix('users');
330
    if ($isModAdmin) {
331
        $query =
332
            "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 "
333
            . $sort_key;
334 View Code Duplication
    } elseif ($xoopsUser) {
335
        $uid   = $xoopsUser->getVar('uid');
336
        $query =
337
            "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 "
338
            . $sort_key;
339
    }
340
    $result = $xoopsDB->query($query);
341
342
    echo "<div style='text-align: center;'>";
343
    echo "<h2 align='center'>" . _MD_LT_RESULTS . ": <a href='index.php?op=viewarticle&amp;artid=$artid' target='quiz_window'><span style='font-weight:bold;font-size:larger;'>$title</span></a></h2>";
344
    echo "<div id='content'>";
345
    echo "<table border='0' cellspacing='1' cellpadding ='3' class='outer' width ='100%'><tr>";
346
    echo "<td align='left' valign='top'><b><a href=index.php>" . _MD_RETURN2INDEX . "</a> -> <a href='index.php?op=listarticles&amp;secid=$secid'>" . _MD_RETURN2QUIZ . '</a> -> ' . _MD_RESULTLIST
347
         . ' (' . _MD_RESULT_SIMPLE . ') </b></td>';
348
    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;'>" . _MD_RESULT_DETAIL
349
         . '</span></a></td>';
350
    echo '</tr></table>';
351
    echo "<table border='0' cellspacing='1' cellpadding ='3' class='outer' width ='100%'>";
352
    echo '<tr>';
353
    echo "<th><a href='index.php?op=viewresults&amp;artid=$artid&amp;sort_key=uname'>" . _MD_LT_STUDENT . '</a></th>';
354
    echo "<th><a href='index.php?op=viewresults&amp;artid=$artid&amp;sort_key=score'>" . _MD_LT_SCORE . '</a></th>';
355
    echo "<th><a href='index.php?op=viewresults&amp;artid=$artid&amp;sort_key=timestamp'>" . _MD_LT_DATE . '</a></th>';
356
    if ($isModAdmin) {
357
        echo "<th colspan=2 align='center'>" . _MD_LT_ACTION . '</th>';
358
    }
359
    echo '</tr>';
360
    while (list($res_id, $quiz_id, $uid, $score, $timestamp, $comment, $uname, $name) = $xoopsDB->fetchRow($result)) {
361
        echo '<tr>';
362 View Code Duplication
        if ($xoopsUser) {
363
            echo "<td class='even'>" . $uname;
364
            if (!empty($name)) {
365
                echo ' (' . $name . ')';
366
            }
367
            echo '</td>';
368
        }
369
        echo "<td class='even' align='center'>$score</td>";
370
        echo "<td class='even' align='center'>$timestamp</td>";
371
        if ($isModAdmin) {
372
            echo "<td class='odd' align='center'><a href='admin/index.php?op=resultdelete&amp;res_id=$res_id'>" . _MD_DELETE . '</a></td>';
373
        }
374
        echo '</tr>';
375
    }
376
    echo '</table>';
377
378
    echo "<table border='0' cellspacing='1' cellpadding ='3' width ='100%'><tr>";
379
    echo "<td align='right'><a href='" . _MD_CREDITSITE . "' target='_credit'/ > Version " . round($xoopsModule->getVar('version') / 100, 2) . '</a></td>';
380
    echo '</tr></table>';
381
    echo '</div>';
382
    echo '</div>';
383
    include dirname(dirname(__DIR__)) . '/footer.php';
384
}
385
386
/**
387
 * @param $artid
388
 * @param $sort_key
389
 */
390
function viewdetails($artid, $sort_key)
391
{
392
    global $xoopsConfig, $xoopsModuleConfig, $xoopsUser, $xoopsDB, $xoopsTheme, $xoopsLogger, $xoopsModule, $xoopsTpl, $isModAdmin, $xoopsUserIsAdmin;
393
    include dirname(dirname(__DIR__)) . '/header.php';
394
    $myts     = MyTextSanitizer::getInstance();
395
    $artid    = (int)$artid;
396
    $sort_key = $myts->addSlashes($sort_key);
397
    //Retrieve table data by users
398
    include __DIR__ . '/module_prefix.php';
399
    $result2 = $xoopsDB->query('SELECT title, posted, secid FROM ' . $xoopsDB->prefix($module_prefix . '_quiz') . " WHERE artid=$artid");
400
    list($title, $posted, $secid) = $xoopsDB->fetchRow($result2);
401
    $title  = $myts->displayTarea($title);
402
    $posted = $myts->displayTarea($posted);
403
    $uid    = $xoopsUser ? $xoopsUser->getVar('uid') : 0;
404
    include __DIR__ . '/module_prefix.php';
405
    $result_db = $xoopsDB->prefix($module_prefix . '_results');
406
    $users_db  = $xoopsDB->prefix('users');
407
    if ($isModAdmin) {
408
        $query =
409
            "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 "
410
            . $sort_key;
411 View Code Duplication
    } elseif ($xoopsUser) {
412
        $query =
413
            "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 "
414
            . $sort_key;
415
    }
416
    $result = $xoopsDB->query($query);
417
418
    echo "<div style='text-align: center;'>";
419
    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;'>" . $title
420
         . '</span></a></h2>';
421
    echo "<div id='content'>";
422
    echo "<table border='0' cellspacing='1' cellpadding ='3' class='outer' width ='100%'><tr>";
423
    echo "<td align='left' valign='top'><b><a href=index.php>" . _MD_RETURN2INDEX . "</a> -> <a href='index.php?op=listarticles&amp;secid=$secid'>" . _MD_RETURN2QUIZ . '</a> -> ' . _MD_RESULTLIST
424
         . ' (' . _MD_RESULT_DETAIL . ') </b></td>';
425
    if ($xoopsUser) {
426
        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;'>" . _MD_RESULT_SIMPLE
427
             . '</span></a></td>';
428
    }
429
    echo '</tr></table>';
430
431
    echo "<table border='0' cellspacing='1' cellpadding ='3' class='outer' width ='100%'>";
432
    echo '<tr>';
433
    echo "<th><a href='index.php?op=viewdetails&amp;artid=$artid&amp;sort_key=uname'>" . _MD_LT_STUDENT . '</a></th>';
434
    echo "<th><a href='index.php?op=viewdetails&amp;artid=$artid&amp;sort_key=score'>" . _MD_LT_SCORE . '</th>';
435
    echo "<th><a href='index.php?op=viewdetails&amp;artid=$artid&amp;sort_key=start_time'>" . _XD_FB_START . '</a></th>';
436
    echo "<th><a href='index.php?op=viewdetails&amp;artid=$artid&amp;sort_key=end_time'>" . _XD_FB_END . '</a></th>';
437
    echo "<th><a href='index.php?op=viewdetails&amp;artid=$artid&amp;sort_key=host'>" . _XD_FB_HOST . '</a></th>';
438
    echo "<th><a href='index.php?op=viewdetails&amp;artid=$artid&amp;sort_key=ip'>" . _XD_FB_IP . '</a></th>';
439
    if ($isModAdmin) {
440
        echo '<th>' . _MD_LT_ACTION . '</th>';
441
    }
442
    echo '</tr>';
443
    while (list($res_id, $quiz_id, $uid, $score, $start_time, $end_time, $timestamp, $host, $ip, $comment, $uname, $name) = $xoopsDB->fetchRow($result)) {
444
        echo '<tr>';
445 View Code Duplication
        if ($xoopsUser) {
446
            echo "<td nowrap class='even'>" . $uname;
447
            if (!empty($name)) {
448
                echo ' (' . $name . ')';
449
            }
450
            echo '</td>';
451
        }
452
        echo "<td class='even' align='center'>$score</td>";
453
        echo "<td class='even' align='center'>$start_time</td>";
454
        echo "<td class='even' align='center'>$end_time</td>";
455
        echo "<td class='even' align='center'>$host</td>";
456
        echo "<td class='even' align='center'>$ip</td>";
457
        if ($isModAdmin) {
458
            echo "<td class='odd' align='center' nowrap><a href='admin/index.php?op=resultdelete&amp;res_id=$res_id'>" . _MD_DELETE . '</td>';
459
        }
460
        echo '</tr>';
461
    }
462
463
    echo '</table>';
464
465
    echo "<table border='0' cellspacing='1' cellpadding ='3' width ='100%'><tr>";
466
    echo "<td align='right'><a href='" . _MD_CREDITSITE . "' target='_credit'/ > Version " . round($xoopsModule->getVar('version') / 100, 2) . '</a></td>';
467
    echo '</tr></table>';
468
    echo '</div>';
469
    echo '</div>';
470
    include dirname(dirname(__DIR__)) . '/footer.php';
471
}
472
473
/**
474
 * @param $sort_key
475
 * @param $secid
476
 */
477
function portfolio($sort_key, $secid)
478
{
479
    global $xoopsConfig, $xoopsModuleConfig, $xoopsUser, $xoopsDB, $xoopsTheme, $xoopsLogger, $xoopsModule, $xoopsTpl, $isModAdmin, $xoopsUserIsAdmin;
480
    include dirname(dirname(__DIR__)) . '/header.php';
481
    $myts     = MyTextSanitizer::getInstance();
482
    $secid    = (int)$secid;
483
    $sort_key = $myts->addSlashes($sort_key);
484
    include __DIR__ . '/module_prefix.php';
485
    $result_db = $xoopsDB->prefix($module_prefix . '_results');
486
    include __DIR__ . '/module_prefix.php';
487
    $quiz_db  = $xoopsDB->prefix($module_prefix . '_quiz');
488
    $users_db = $xoopsDB->prefix('users');
489
    if ($secid == 0) {
490
        $section_query = '';
491
    } else {
492
        $section_query = "AND $quiz_db.secid = $secid ";
493
    }
494
    if ($isModAdmin) {
495
        $query     =
496
            "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 "
497
            . $section_query . ' ORDER BY ' . $sort_key;
498
        $user_name = '';
499
    } elseif ($xoopsUser) {
500
        $user_id   = $xoopsUser->getVar('uid');
501
        $user_name = ' (' . $xoopsUser->getVar('uname') . ')';
502
        $query     =
503
            "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 "
504
            . $section_query . ' ORDER BY ' . $sort_key;
505
    } else {
506
        $user_name = '';
507
    }
508
    $result = $xoopsDB->query($query);
509
510
    echo "<div style='text-align: center;'>";
511
    echo "<h2 align='center'>" . _MD_LT_PORTFOLIO . $user_name . '</h2>';
512
    echo "<div id='content'>";
513
    echo "<table border='0' cellspacing='1' cellpadding ='3' class='outer' width ='100%'>";
514
    echo "<form action='index.php?' method='get'><tr>";
515
    echo "<td align='left' valign='top'><b><a href=index.php>" . _MD_RETURN2INDEX . '</a> -> ' . _MD_LT_PORTFOLIO . '</td>';
516
    echo "<td align='right' valign='center'>" . _MD_SECNAMEC . "<input type='hidden' name='op' value='portfolio'>" . "<input type='hidden' name='sort_key' value='timestamp'>"
517
         . "<select name='secid'>";
518
519
    if ($secid == 0) {
520
        echo "<option value='0' selected>" . _MD_ALL . '</option>';
521
    } else {
522
        echo "<option value='0'>" . _MD_ALL . '</option>';
523
    }
524
    include __DIR__ . '/module_prefix.php';
525
    $courses = $xoopsDB->query('SELECT secid, secname FROM ' . $xoopsDB->prefix($module_prefix . '_sections') . ' ORDER BY secname');
526
    while (list($secid2list, $secname) = $xoopsDB->fetchRow($courses)) {
527
        $secname = $myts->displayTarea($secname);
528
        if ($secid2list == $secid) {
529
            echo "<option value='$secid2list' selected>$secname</option>";
530
        } else {
531
            echo "<option value='$secid2list'>$secname</option>";
532
        }
533
    }
534
535
    echo "</select><input type='submit' value='" . _MD_GO . "'></td>";
536
    echo '</tr></form></table>';
537
    echo "<table border='0' cellspacing='1' cellpadding ='3' class='outer' width ='100%'>";
538
    echo '<tr>';
539
    if ($isModAdmin) {
540
        echo "<th><a href='index.php?op=portfolio&amp;sort_key=uname'>" . _MD_LT_STUDENT . '</a></th>';
541
    }
542
    echo "<th><a href='index.php?op=portfolio&amp;sort_key=title'>" . _MD_LT_TITLE2 . '</a></th>';
543
    echo "<th><a href='index.php?op=portfolio&amp;sort_key=score'>" . _MD_LT_SCORE . '</a></th>';
544
    echo "<th><a href='index.php?op=portfolio&amp;sort_key=timestamp'>" . _MD_LT_DATE . '</a></th>';
545
    if ($isModAdmin) {
546
        echo "<th colspan=2 align='center'>" . _MD_LT_ACTION . '</th>';
547
    }
548
    echo '</tr>';
549
    while (list($res_id, $quiz_id, $uid, $score, $start_time, $end_time, $timestamp, $host, $ip, $comment, $artid, $secid, $title, $uid2, $uname, $name) = $xoopsDB->fetchRow($result)) {
550
        echo '<tr>';
551
        if ($isModAdmin) {
552
            echo "<td class='even'>" . $uname;
553
            if (!empty($name)) {
554
                echo ' (' . $name . ')';
555
            }
556
            echo '</td>';
557
        }
558
        echo "<td class='even'><a href='index.php?op=viewarticle&amp;artid=$artid' target='quiz_window'>$title</a></td>";
559
        echo "<td class='even' align='center'>$score</td>";
560
        echo "<td class='even' align='center'>$timestamp</td>";
561
        if ($isModAdmin) {
562
            echo "<td class='odd' align='center'><a href='admin/index.php?op=resultdelete&amp;res_id=$res_id'>" . _MD_DELETE . '</a></td>';
563
        }
564
        echo '</tr>';
565
    }
566
    echo '</table>';
567
568
    echo "<table border='0' cellspacing='1' cellpadding ='3' width ='100%'><tr>";
569
    echo "<td align='right'><a href='" . _MD_CREDITSITE . "' target='_credit'/ > Version " . round($xoopsModule->getVar('version') / 100, 2) . '</a></td>';
570
    echo '</tr></table>';
571
    echo '</div>';
572
    echo '</div>';
573
    include dirname(dirname(__DIR__)) . '/footer.php';
574
}
575
576
$op       = XoopsRequest::getString('op', '', 'GET');
577
$secid    = XoopsRequest::getInt('secid', 0, 'GET');
578
$page     = XoopsRequest::getInt('page', 0, 'GET');
579
$artid    = XoopsRequest::getInt('artid', 0, 'GET');
580
$uid      = XoopsRequest::getInt('uid', 0, 'GET');
581
$sort_key = XoopsRequest::getString('sort_key', 'uname', 'GET');
582
583
switch ($op) {
584
    case 'viewarticle':
585
        viewarticle($artid);
586
        break;
587
    case 'listarticles':
588
        listarticles($secid);
589
        break;
590
    case 'viewresults':
591
        viewresults($artid, $sort_key);
592
        break;
593
    case 'viewdetails':
594
        viewdetails($artid, $sort_key);
595
        break;
596
    case 'portfolio':
597
        portfolio($sort_key, $secid);
598
        break;
599
    default:
600
        listsections();
601
        break;
602
}
603