Completed
Pull Request — master (#6)
by Michael
02:04
created

index.php (2 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 '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 'module_prefix.php';
60
    $result = $xoopsDB->query(
61
        "SELECT secid, secname, secdesc, display, expire FROM " . $xoopsDB->prefix($module_prefix . "_sections")
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       = intval($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 'module_prefix.php';
105
            $result_db = $xoopsDB->prefix($module_prefix . '_results');
106
            include '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 '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') {
0 ignored issues
show
This code seems to be duplicated across your project.

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

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

Loading history...
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 '../../footer.php';
149
}
150
151
function listarticles($secid)
152
{
153
    global $xoopsConfig, $xoopsModuleConfig, $xoopsUser, $xoopsDB, $xoopsTheme, $xoopsLogger, $xoopsModule, $xoopsTpl, $isModAdmin, $xoopsUserIsAdmin;
154
    include '../../header.php';
155
    $myts  =& MyTextSanitizer::getInstance();
156
    $secid = intval($secid);
157
    include 'module_prefix.php';
158
    $result = $xoopsDB->query(
159
        "SELECT secname, secdesc, display, expire FROM " . $xoopsDB->prefix($module_prefix . "_sections") . " WHERE secid=$secid"
160
    );
161
    list($secname, $secdesc, $display, $expire) = $xoopsDB->fetchRow($result);
162
    $secname = $myts->displayTarea($myts->stripSlashesGPC($secname));
163
    $secdesc = $myts->displayTarea($myts->stripSlashesGPC($secdesc));
164
    $display = intval($display);
165
    $expire  = $myts->displayTarea($myts->stripSlashesGPC($expire));
166
    // Trap for hidden or expired items
167
    if (!$display) {
168
        redirect_header("index.php", 2, _AM_MSG_ACCESS_ERROR);
169
    } elseif ($expire != '0000-00-00 00:00:00' && $expire < formatTimestamp(time(), "Y-m-d H:i:s")) {
170
        redirect_header("index.php", 2, _AM_MSG_ACCESS_ERROR);
171
    }
172
    include 'module_prefix.php';
173
    $result = $xoopsDB->query(
174
        "SELECT artid, secid, title, posted, counter, display, expire FROM " . $xoopsDB->prefix(
175
            $module_prefix . "_quiz"
176
        ) . " WHERE secid=$secid" . " ORDER BY title"
177
    );
178
    echo "<div style='text-align: center;'>";
179
    echo "<h2 align='center'>$secname</h2>";
180
    echo "<h4 align='center'>" . _MD_THEFOLLOWING . "</h4>";
181
    echo "<div id='content'>";
182
    echo "<table border='0' cellspacing='1' cellpadding ='3' class='outer' width ='100%'><tr>";
183
    echo "<td align='left' valign='top'><b><a href=index.php>" . _MD_RETURN2INDEX . "</a> -> " . _MD_RETURN2QUIZ
184
        . "</b></td>";
185
    if ($xoopsUser) {
186
        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;'>"
187
            . _MD_LT_PORTFOLIO . "</span></a></td>";
188
        $alert = "";
189
    } else {
190
        $alert = " onClick='alert(\"" . _MD_ALERTGUEST . "\")'";
191
    }
192
    echo "</tr></table>";
193
    echo "<table border='0' cellspacing='1' cellpadding ='3' class='outer' width ='100%'>";
194
    echo "<tr>";
195
    echo "<th>" . _MD_LT_TITLE . "</th>";
196
    echo "<th>" . _XD_FB_FINISHED_BY . "</th>";
197
    if ($isModAdmin) {
198
        echo "<th>" . _MD_LT_SITEAVG . "</th>";
199
    } elseif ($xoopsUser) {
200
        echo "<th>" . _MD_LT_MYMAX . "</th>";
201
    }
202
    echo "<th>" . _MD_LT_SITEMAX . "</th>";
203
    echo "<th>" . _MD_LT_EXPIRE . "</th>";
204
    if ($xoopsUser) {
205
        echo "<th colspan=3>" . _MD_LT_ACTION . "</th>";
206
    }
207
    echo "</tr>";
208
    $currenttime = formatTimestamp(time(), "Y-m-d H:i:s");
209
    while (list($artid, $secid, $title, $posted, $counter, $display, $expire) = $xoopsDB->fetchRow($result)) {
210
        if ($display) {
211
            $title  = $myts->displayTarea($title);
212
            $expire = $myts->stripSlashesGPC($expire);
213
            echo "<tr>";
214
            if ($expire != '0000-00-00 00:00:00' && $expire < $currenttime) {
215
                echo "<td class='even'>$title</td>";
216
            } else {
217
                echo "<td class='even'><a href='index.php?op=viewarticle&amp;artid=$artid' target='quiz_window' $alert><b>$title</b></a></td>";
218
            }
219
            if ($xoopsUser) {
220
                $uid = $xoopsUser->getVar('uid');
221
                include 'module_prefix.php';
222
                $query1 = "SELECT DISTINCT uid FROM " . $xoopsDB->prefix($module_prefix . '_results')
223
                    . " WHERE quiz_id=$artid";
224
                include 'module_prefix.php';
225
                $query2 = "SELECT score FROM " . $xoopsDB->prefix($module_prefix . '_results')
226
                    . " WHERE quiz_id=$artid AND uid=$uid";
227
                if ($isModAdmin) {
228
                    $results_exist = $xoopsDB->query($query1);
229
                    $done_by       = $xoopsDB->query($query1);
230
                } else {
231
                    $results_exist = $xoopsDB->query($query2);
232
                    $done_by       = $xoopsDB->query($query1);
233
                }
234
                $results_exist = $xoopsDB->getRowsNum($results_exist);
235
            } else {
236
                include 'module_prefix.php';
237
                $query1  = "SELECT DISTINCT uid FROM " . $xoopsDB->prefix($module_prefix . '_results')
238
                    . " WHERE quiz_id=$artid";
239
                $done_by = $xoopsDB->query($query1);
240
            }
241
            $done_by = $xoopsDB->getRowsNum($done_by);
242
            echo "<td class='even' align='center'>$done_by</td>";
243
            include 'module_prefix.php';
244
            $site_max = $xoopsDB->query(
245
                "SELECT MAX(score), AVG(score) FROM " . $xoopsDB->prefix($module_prefix . '_results') . " WHERE quiz_id = $artid"
246
            );
247
            list($site_max, $site_avg) = $xoopsDB->fetchRow($site_max);
248
            if ($isModAdmin) {
249
                echo "<td class='even' align='center'>" . round($site_avg) . "</td>";
250
            } elseif ($xoopsUser) {
251
                include 'module_prefix.php';
252
                $my_max = $xoopsDB->query(
253
                    "SELECT MAX(score) FROM " . $xoopsDB->prefix($module_prefix . '_results') . " WHERE uid = $uid AND quiz_id = $artid"
254
                );
255
                list($my_max) = $xoopsDB->fetchRow($my_max);
256
                echo "<td class='even' align='center'>$my_max</td>";
257
            }
258
            echo "<td class='even' align='center'>$site_max</td>";
259 View Code Duplication
            if ($expire != '0000-00-00 00:00:00') {
260
                if ($expire > $currenttime) {
261
                    echo "<td class='even'>" . $expire . "</td>";
262
                } else {
263
                    echo "<td class='even'>" . $expire . "<span style='color:#ff0000;'>(" . _MD_LT_EXPIRED
264
                        . ")</span></td>";
265
                }
266
            } else {
267
                echo "<td class='even'>" . '-------------------' . "</td>";
268
            }
269
            if ($xoopsUser) {
270
                if ($results_exist) {
271
                    echo "<td class='odd' align='center'><a href='index.php?op=viewresults&amp;artid=$artid&amp;sort_key=timestamp'>"
272
                        . _MD_LT_RESULTS . "</a></td>";
273
                } else {
274
                    echo "<td class='odd' align='center'>&nbsp;</td>";
275
                }
276
            }
277
            if ($isModAdmin) {
278
                echo "<td class='odd' align='center'><a href='admin/index.php?op=secartedit&amp;artid=$artid'>"
279
                    . _MD_EDIT . "</a></td>";
280
                echo "<td class='odd' align='center'><a href='admin/index.php?op=secartdelete&amp;artid=$artid'>"
281
                    . _MD_DELETE . "</a></td>";
282
            }
283
            echo "</tr>";
284
        }
285
    }
286
    echo "</table>";
287
    echo "<table border='0' cellspacing='1' cellpadding ='3' width ='100%'><tr>";
288
    echo "<td align='right'><a href='" . _MD_CREDITSITE . "' target='_credit'/ > Version " . round(
289
            $xoopsModule->getVar('version') / 100,
290
            2
291
        ) . "</a></td>";
292
    echo "</tr></table>";
293
    echo "</div>";
294
    echo "</div>";
295
    include '../../footer.php';
296
}
297
298
function viewarticle($artid)
299
{
300
    global $xoopsConfig, $xoopsModuleConfig, $xoopsUser, $xoopsDB, $xoopsTpl, $isModAdmin, $xoopsUserIsAdmin;
301
    $myts  =& MyTextSanitizer::getInstance();
302
    $artid = intval($artid);
303
    include 'module_prefix.php';
304
    $result = $xoopsDB->query(
305
        "SELECT secid, title, content, display, expire FROM " . $xoopsDB->prefix($module_prefix . "_quiz") . " WHERE artid=$artid"
306
    );
307
    list($secid, $title, $content, $display, $expire) = $xoopsDB->fetchRow($result);
308
    $secid       = intval($secid);
309
    $display     = intval($display);
310
    $expire      = $myts->stripSlashesGPC($expire);
311
    $currenttime = formatTimestamp(time(), "Y-m-d H:i:s");
312
    if ($display) {
313
        include 'module_prefix.php';
314
        $result2 = $xoopsDB->query(
315
            "SELECT display, expire FROM " . $xoopsDB->prefix($module_prefix . "_sections") . " WHERE secid=$secid"
316
        );
317
        list($display2, $expire2) = $xoopsDB->fetchRow($result2);
318
        $display2 = intval($display2);
319
        $expire2  = $myts->stripSlashesGPC($expire2);
320
        if ($display2) {
321
            if ($expire2 == '0000-00-00 00:00:00' || $expire2 > $currenttime) {
322
                if ($expire == '0000-00-00 00:00:00' || $expire > $currenttime) {
323
                    setcookie("xoopsHP_file_id", $artid);
324
                    $title = $myts->displayTarea($title);
325
                    // Can't decide an appropriate sanitizer...
326
                    //$content = $myts->displayTarea($content, 1);
327
                    echo $content;
328
                } else {
329
                    redirect_header("index.php", 2, _AM_MSG_ACCESS_ERROR);
330
                }
331
            } else {
332
                redirect_header("index.php", 2, _AM_MSG_ACCESS_ERROR);
333
            }
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
}
341
342
function viewresults($artid, $sort_key)
343
{
344
    global $xoopsConfig, $xoopsModuleConfig, $xoopsUser, $xoopsDB, $xoopsTheme, $xoopsLogger, $xoopsModule, $xoopsTpl, $isModAdmin, $xoopsUserIsAdmin;
345
    include '../../header.php';
346
    $myts =& MyTextSanitizer::getInstance();
347
348
    //Retrieve table data by users
349
    $artid = intval($artid);
350
    include 'module_prefix.php';
351
    $result2 = $xoopsDB->query(
352
        "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...
353
    );
354
    list($title, $posted, $secid) = $xoopsDB->fetchRow($result2);
355
    $title  = $myts->displayTarea($title);
356
    $posted = $myts->displayTarea($posted);
357
    include 'module_prefix.php';
358
    $result_db = $xoopsDB->prefix($module_prefix . '_results');
359
    $users_db  = $xoopsDB->prefix('users');
360
    if ($isModAdmin) {
361
        $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 "
362
            . $sort_key;
363 View Code Duplication
    } elseif ($xoopsUser) {
364
        $uid   = $xoopsUser->getVar('uid');
365
        $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 "
366
            . $sort_key;
367
    }
368
    $result = $xoopsDB->query($query);
369
370
    echo "<div style='text-align: center;'>";
371
    echo "<h2 align='center'>" . _MD_LT_RESULTS
372
        . ": <a href='index.php?op=viewarticle&amp;artid=$artid' target='quiz_window'><span style='font-weight:bold;font-size:larger;'>$title</span></a></h2>";
373
    echo "<div id='content'>";
374
    echo "<table border='0' cellspacing='1' cellpadding ='3' class='outer' width ='100%'><tr>";
375
    echo "<td align='left' valign='top'><b><a href=index.php>" . _MD_RETURN2INDEX . "</a> -> <a href='index.php?op=listarticles&amp;secid=$secid'>"
376
        . _MD_RETURN2QUIZ . "</a> -> " . _MD_RESULTLIST . " (" . _MD_RESULT_SIMPLE . ") </b></td>";
377
    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;'>"
378
        . _MD_RESULT_DETAIL . "</span></a></td>";
379
    echo "</tr></table>";
380
    echo "<table border='0' cellspacing='1' cellpadding ='3' class='outer' width ='100%'>";
381
    echo "<tr>";
382
    echo "<th><a href='index.php?op=viewresults&amp;artid=$artid&amp;sort_key=uname'>" . _MD_LT_STUDENT . "</a></th>";
383
    echo "<th><a href='index.php?op=viewresults&amp;artid=$artid&amp;sort_key=score'>" . _MD_LT_SCORE . "</a></th>";
384
    echo "<th><a href='index.php?op=viewresults&amp;artid=$artid&amp;sort_key=timestamp'>" . _MD_LT_DATE . "</a></th>";
385
    if ($isModAdmin) {
386
        echo "<th colspan=2 align='center'>" . _MD_LT_ACTION . "</th>";
387
    }
388
    echo "</tr>";
389
    while (list($res_id, $quiz_id, $uid, $score, $timestamp, $comment, $uname, $name) = $xoopsDB->fetchRow($result)) {
390
        echo "<tr>";
391 View Code Duplication
        if ($xoopsUser) {
392
            echo "<td class='even'>" . $uname;
393
            if (!empty($name)) {
394
                echo " (" . $name . ")";
395
            }
396
            echo "</td>";
397
        }
398
        echo "<td class='even' align='center'>$score</td>";
399
        echo "<td class='even' align='center'>$timestamp</td>";
400
        if ($isModAdmin) {
401
            echo "<td class='odd' align='center'><a href='admin/index.php?op=resultdelete&amp;res_id=$res_id'>"
402
                . _MD_DELETE . "</a></td>";
403
        }
404
        echo "</tr>";
405
    }
406
    echo "</table>";
407
408
    echo "<table border='0' cellspacing='1' cellpadding ='3' width ='100%'><tr>";
409
    echo "<td align='right'><a href='" . _MD_CREDITSITE . "' target='_credit'/ > Version " . round(
410
            $xoopsModule->getVar('version') / 100,
411
            2
412
        ) . "</a></td>";
413
    echo "</tr></table>";
414
    echo "</div>";
415
    echo "</div>";
416
    include '../../footer.php';
417
}
418
419
function viewdetails($artid, $sort_key)
420
{
421
    global $xoopsConfig, $xoopsModuleConfig, $xoopsUser, $xoopsDB, $xoopsTheme, $xoopsLogger, $xoopsModule, $xoopsTpl, $isModAdmin, $xoopsUserIsAdmin;
422
    include '../../header.php';
423
    $myts     =& MyTextSanitizer::getInstance();
424
    $artid    = intval($artid);
425
    $sort_key = $myts->addSlashes($sort_key);
426
    //Retrieve table data by users
427
    include 'module_prefix.php';
428
    $result2 = $xoopsDB->query(
429
        "SELECT title, posted, secid FROM " . $xoopsDB->prefix($module_prefix . "_quiz") . " WHERE artid=$artid"
430
    );
431
    list($title, $posted, $secid) = $xoopsDB->fetchRow($result2);
432
    $title  = $myts->displayTarea($title);
433
    $posted = $myts->displayTarea($posted);
434
    $uid    = ($xoopsUser) ? $xoopsUser->getVar('uid') : 0;
435
    include 'module_prefix.php';
436
    $result_db = $xoopsDB->prefix($module_prefix . '_results');
437
    $users_db  = $xoopsDB->prefix('users');
438
    if ($isModAdmin) {
439
        $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 "
440
            . $sort_key;
441 View Code Duplication
    } elseif ($xoopsUser) {
442
        $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 "
443
            . $sort_key;
444
    }
445
    $result = $xoopsDB->query($query);
446
447
    echo "<div style='text-align: center;'>";
448
    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;'>"
449
        . $title . "</span></a></h2>";
450
    echo "<div id='content'>";
451
    echo "<table border='0' cellspacing='1' cellpadding ='3' class='outer' width ='100%'><tr>";
452
    echo "<td align='left' valign='top'><b><a href=index.php>" . _MD_RETURN2INDEX . "</a> -> <a href='index.php?op=listarticles&amp;secid=$secid'>"
453
        . _MD_RETURN2QUIZ . "</a> -> " . _MD_RESULTLIST . " (" . _MD_RESULT_DETAIL . ") </b></td>";
454
    if ($xoopsUser) {
455
        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;'>"
456
            . _MD_RESULT_SIMPLE . "</span></a></td>";
457
    }
458
    echo "</tr></table>";
459
460
    echo "<table border='0' cellspacing='1' cellpadding ='3' class='outer' width ='100%'>";
461
    echo "<tr>";
462
    echo "<th><a href='index.php?op=viewdetails&amp;artid=$artid&amp;sort_key=uname'>" . _MD_LT_STUDENT . "</a></th>";
463
    echo "<th><a href='index.php?op=viewdetails&amp;artid=$artid&amp;sort_key=score'>" . _MD_LT_SCORE . "</th>";
464
    echo
465
        "<th><a href='index.php?op=viewdetails&amp;artid=$artid&amp;sort_key=start_time'>" . _XD_FB_START . "</a></th>";
466
    echo "<th><a href='index.php?op=viewdetails&amp;artid=$artid&amp;sort_key=end_time'>" . _XD_FB_END . "</a></th>";
467
    echo "<th><a href='index.php?op=viewdetails&amp;artid=$artid&amp;sort_key=host'>" . _XD_FB_HOST . "</a></th>";
468
    echo "<th><a href='index.php?op=viewdetails&amp;artid=$artid&amp;sort_key=ip'>" . _XD_FB_IP . "</a></th>";
469
    if ($isModAdmin) {
470
        echo "<th>" . _MD_LT_ACTION . "</th>";
471
    }
472
    echo "</tr>";
473
    while (
474
    list($res_id, $quiz_id, $uid, $score, $start_time, $end_time, $timestamp, $host, $ip, $comment, $uname, $name)
475
        = $xoopsDB->fetchRow($result)) {
476
        echo "<tr>";
477 View Code Duplication
        if ($xoopsUser) {
478
            echo "<td nowrap class='even'>" . $uname;
479
            if (!empty($name)) {
480
                echo " (" . $name . ")";
481
            }
482
            echo "</td>";
483
        }
484
        echo "<td class='even' align='center'>$score</td>";
485
        echo "<td class='even' align='center'>$start_time</td>";
486
        echo "<td class='even' align='center'>$end_time</td>";
487
        echo "<td class='even' align='center'>$host</td>";
488
        echo "<td class='even' align='center'>$ip</td>";
489
        if ($isModAdmin) {
490
            echo "<td class='odd' align='center' nowrap><a href='admin/index.php?op=resultdelete&amp;res_id=$res_id'>"
491
                . _MD_DELETE . "</td>";
492
        }
493
        echo "</tr>";
494
    }
495
496
    echo "</table>";
497
498
    echo "<table border='0' cellspacing='1' cellpadding ='3' width ='100%'><tr>";
499
    echo "<td align='right'><a href='" . _MD_CREDITSITE . "' target='_credit'/ > Version " . round(
500
            $xoopsModule->getVar('version') / 100,
501
            2
502
        ) . "</a></td>";
503
    echo "</tr></table>";
504
    echo "</div>";
505
    echo "</div>";
506
    include '../../footer.php';
507
}
508
509
function portfolio($sort_key, $secid)
510
{
511
    global $xoopsConfig, $xoopsModuleConfig, $xoopsUser, $xoopsDB, $xoopsTheme, $xoopsLogger, $xoopsModule, $xoopsTpl, $isModAdmin, $xoopsUserIsAdmin;
512
    include '../../header.php';
513
    $myts     =& MyTextSanitizer::getInstance();
514
    $secid    = intval($secid);
515
    $sort_key = $myts->addSlashes($sort_key);
516
    include 'module_prefix.php';
517
    $result_db = $xoopsDB->prefix($module_prefix . '_results');
518
    include 'module_prefix.php';
519
    $quiz_db  = $xoopsDB->prefix($module_prefix . '_quiz');
520
    $users_db = $xoopsDB->prefix('users');
521
    if ($secid == 0) {
522
        $section_query = "";
523
    } else {
524
        $section_query = "AND $quiz_db.secid = $secid ";
525
    }
526
    if ($isModAdmin) {
527
        $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 "
528
            . $section_query . " ORDER BY " . $sort_key;
529
        $user_name = "";
530
    } elseif ($xoopsUser) {
531
        $user_id   = $xoopsUser->getVar('uid');
532
        $user_name = " (" . $xoopsUser->getVar('uname') . ")";
533
        $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 "
534
            . $section_query . " ORDER BY " . $sort_key;
535
    } else {
536
        $user_name = "";
537
    }
538
    $result = $xoopsDB->query($query);
539
540
    echo "<div style='text-align: center;'>";
541
    echo "<h2 align='center'>" . _MD_LT_PORTFOLIO . $user_name . "</h2>";
542
    echo "<div id='content'>";
543
    echo "<table border='0' cellspacing='1' cellpadding ='3' class='outer' width ='100%'>";
544
    echo "<form action='index.php?' method='get'><tr>";
545
    echo "<td align='left' valign='top'><b><a href=index.php>" . _MD_RETURN2INDEX . "</a> -> " . _MD_LT_PORTFOLIO
546
        . "</td>";
547
    echo "<td align='right' valign='center'>" . _MD_SECNAMEC . "<input type='hidden' name='op' value='portfolio'>"
548
        . "<input type='hidden' name='sort_key' value='timestamp'>" . "<select name='secid'>";
549
550
    if ($secid == 0) {
551
        echo "<option value='0' selected>" . _MD_ALL . "</option>";
552
    } else {
553
        echo "<option value='0'>" . _MD_ALL . "</option>";
554
    }
555
    include 'module_prefix.php';
556
    $courses = $xoopsDB->query(
557
        "SELECT secid, secname FROM " . $xoopsDB->prefix($module_prefix . "_sections") . " ORDER BY secname"
558
    );
559
    while (list($secid2list, $secname) = $xoopsDB->fetchRow($courses)) {
560
        $secname = $myts->displayTarea($secname);
561
        if ($secid2list == $secid) {
562
            echo "<option value='$secid2list' selected>$secname</option>";
563
        } else {
564
            echo "<option value='$secid2list'>$secname</option>";
565
        }
566
    }
567
568
    echo "</select><input type='submit' value='" . _MD_GO . "'></td>";
569
    echo "</tr></form></table>";
570
    echo "<table border='0' cellspacing='1' cellpadding ='3' class='outer' width ='100%'>";
571
    echo "<tr>";
572
    if ($isModAdmin) {
573
        echo "<th><a href='index.php?op=portfolio&amp;sort_key=uname'>" . _MD_LT_STUDENT . "</a></th>";
574
    }
575
    echo "<th><a href='index.php?op=portfolio&amp;sort_key=title'>" . _MD_LT_TITLE2 . "</a></th>";
576
    echo "<th><a href='index.php?op=portfolio&amp;sort_key=score'>" . _MD_LT_SCORE . "</a></th>";
577
    echo "<th><a href='index.php?op=portfolio&amp;sort_key=timestamp'>" . _MD_LT_DATE . "</a></th>";
578
    if ($isModAdmin) {
579
        echo "<th colspan=2 align='center'>" . _MD_LT_ACTION . "</th>";
580
    }
581
    echo "</tr>";
582
    while (
583
    list($res_id, $quiz_id, $uid, $score, $start_time, $end_time, $timestamp, $host, $ip, $comment, $artid, $secid,
584
        $title, $uid2, $uname, $name)
585
        = $xoopsDB->fetchRow($result)) {
586
        echo "<tr>";
587
        if ($isModAdmin) {
588
            echo "<td class='even'>" . $uname;
589
            if (!empty($name)) {
590
                echo " (" . $name . ")";
591
            }
592
            echo "</td>";
593
        }
594
        echo "<td class='even'><a href='index.php?op=viewarticle&amp;artid=$artid' target='quiz_window'>$title</a></td>";
595
        echo "<td class='even' align='center'>$score</td>";
596
        echo "<td class='even' align='center'>$timestamp</td>";
597
        if ($isModAdmin) {
598
            echo "<td class='odd' align='center'><a href='admin/index.php?op=resultdelete&amp;res_id=$res_id'>"
599
                . _MD_DELETE . "</a></td>";
600
        }
601
        echo "</tr>";
602
    }
603
    echo "</table>";
604
605
    echo "<table border='0' cellspacing='1' cellpadding ='3' width ='100%'><tr>";
606
    echo "<td align='right'><a href='" . _MD_CREDITSITE . "' target='_credit'/ > Version " . round(
607
            $xoopsModule->getVar('version') / 100,
608
            2
609
        ) . "</a></td>";
610
    echo "</tr></table>";
611
    echo "</div>";
612
    echo "</div>";
613
    include '../../footer.php';
614
}
615
616
$op = isset($HTTP_GET_VARS['op']) ? trim($HTTP_GET_VARS['op']) : '';
617
$secid = isset($HTTP_GET_VARS['secid']) ? intval($HTTP_GET_VARS['secid']) : 0;
618
$page = isset($HTTP_GET_VARS['page']) ? intval($HTTP_GET_VARS['page']) : 0;
619
$artid = isset($HTTP_GET_VARS['artid']) ? intval($HTTP_GET_VARS['artid']) : 0;
620
$uid = isset($HTTP_GET_VARS['uid']) ? intval($HTTP_GET_VARS['uid']) : 0;
621
$sort_key = isset($HTTP_GET_VARS['sort_key']) ? trim($HTTP_GET_VARS['sort_key']) : "uname";
622
623
switch ($op) {
624
    case "viewarticle":
625
        viewarticle($artid);
626
        break;
627
    case "listarticles":
628
        listarticles($secid);
629
        break;
630
    case "viewresults":
631
        viewresults($artid, $sort_key);
632
        break;
633
    case "viewdetails":
634
        viewdetails($artid, $sort_key);
635
        break;
636
    case "portfolio":
637
        portfolio($sort_key, $secid);
638
        break;
639
    default:
640
        listsections();
641
        break;
642
}
643