-
Notifications
You must be signed in to change notification settings - Fork 6
/
show_results_assessment.php
163 lines (130 loc) · 7.56 KB
/
show_results_assessment.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?php
/*
OWASP ASVS Assessment Tool (OWAAT)
Copyright (C) 2014 Mahmoud Ghorbanzadeh <mdgh (a) aut.ac.ir>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
include 'settings.php';
include 'function.php';
if(!isset($_SESSION['admin']))
error($PN.'10');
header('Content-Type: text/html; charset=utf-8');
include 'db.php';
if(isset($_GET["assessment_id"]) && isset($_GET["users_id"]) && isset($_GET["chapters_id"]))
{
$assessment_id = (int) $_GET["assessment_id"];
$users_id_array = explode(",", $_GET['users_id']);
$users_id = '';
foreach($users_id_array as $userID)
{
if($users_id != '')
$users_id .= ',';
$userID = trim($userID);
$users_id .= (int)$userID;
}
$chapters_id_array = explode(",", $_GET['chapters_id']);
$chapters_id = '';
foreach($chapters_id_array as $chapterID)
{
if($chapters_id != '')
$chapters_id .= ',';
$chapterID = trim($chapterID);
$chapters_id .= (int)$chapterID;
}
}
else
error($PN.'11');
if(isset($_GET["jtSorting"]) && isset($_GET["jtStartIndex"]) && isset($_GET["jtPageSize"]))
{
$Sorting_array_multiple = explode(",", $_GET['jtSorting']);
$sort = '';
foreach($Sorting_array_multiple as $Sorting)
{
$Sorting = trim($Sorting);
$Sorting_array = explode(" ", $Sorting);
if($sort != '')
$sort .= ', ';
if(!isset($Sorting_array[0]) || !isset($Sorting_array[1]))
error($PN.'12');
switch ($Sorting_array[0]) {
case "chapter_id":
$sort .= 'G.chapter_id';
break;
case "rule_number":
$sort .= 'G.rule_number';
break;
case "title":
$sort .= 'G.title';
break;
case "uname":
$sort .= 'G.uname';
break;
case "PassOrFail":
$sort .= 'H.PassOrFail';
break;
case "comment":
$sort .= 'H.comment';
break;
case "last_modified":
$sort .= 'H.last_modified';
break;
default:
error($PN.'13');
}
if($Sorting_array[1] == 'ASC')
$sort .= ' ASC';
else
$sort .= ' DESC';
}
$Sorting = $sort;
$StartIndex = (int)$_GET['jtStartIndex'];
$PageSize = (int)$_GET['jtPageSize'];
}
else
error($PN.'14');
$assignment_chapters_id = '';
if($users_id != 0 && $chapters_id != 0)
$result_assignment_chapters_id = mysql_query("SELECT id FROM assignment_chapter WHERE assignment_id IN (SELECT id FROM assignment WHERE assessment_id = ".$assessment_id." AND user_id IN (".$users_id.")) AND chapter_id IN (".$chapters_id.")") or error($PN.'15');
else if($users_id != 0 && $chapters_id == 0)
$result_assignment_chapters_id = mysql_query("SELECT id FROM assignment_chapter WHERE assignment_id IN (SELECT id FROM assignment WHERE assessment_id = ".$assessment_id." AND user_id IN (".$users_id.")) AND chapter_id IN (SELECT id FROM chapters WHERE id IN (SELECT chapter_id FROM assignment_chapter WHERE assignment_id IN (SELECT id FROM assignment WHERE assessment_id = ".$assessment_id." and user_id IN (SELECT user_id FROM (SELECT user_id from assignment WHERE assessment_id=".$assessment_id.") AS A LEFT JOIN (SELECT id FROM users) AS B on A.user_id = B.id)) ORDER BY id))") or error($PN.'16');
else if($users_id == 0 && $chapters_id != 0)
$result_assignment_chapters_id = mysql_query("SELECT id FROM assignment_chapter WHERE assignment_id IN (SELECT id FROM assignment WHERE assessment_id = ".$assessment_id." AND user_id IN (SELECT user_id FROM (SELECT user_id from assignment WHERE assessment_id=".$assessment_id.") AS A LEFT JOIN (SELECT id FROM users) AS B on A.user_id = B.id ORDER BY id)) AND chapter_id IN (".$chapters_id.")") or error($PN.'17');
else
$result_assignment_chapters_id = mysql_query("SELECT id FROM assignment_chapter WHERE assignment_id IN (SELECT id FROM assignment WHERE assessment_id = ".$assessment_id." AND user_id IN (SELECT user_id FROM (SELECT user_id from assignment WHERE assessment_id=".$assessment_id.") AS A LEFT JOIN (SELECT id FROM users) AS B on A.user_id = B.id ORDER BY id)) AND chapter_id IN (SELECT id FROM chapters WHERE id IN (SELECT chapter_id FROM assignment_chapter WHERE assignment_id IN (SELECT id FROM assignment WHERE assessment_id = ".$assessment_id." and user_id IN (SELECT user_id FROM (SELECT user_id from assignment WHERE assessment_id=".$assessment_id.") AS A LEFT JOIN (SELECT id FROM users) AS B on A.user_id = B.id)) ORDER BY id))") or error($PN.'18');
while($row_assignment_chapters_id = mysql_fetch_array($result_assignment_chapters_id))
{
if($row_assignment_chapters_id['id'] > 0)//It has value
{
if($assignment_chapters_id == '')
$assignment_chapters_id = $row_assignment_chapters_id['id'];
else
$assignment_chapters_id .= ','.$row_assignment_chapters_id['id'];
}
}
if($assignment_chapters_id == '')
error($PN.'19');
$result = mysql_query("SELECT COUNT(*) AS RecordCount FROM (SELECT E.assignment_id, E.id FROM (SELECT A.assignment_id, B.id, B.chapter_id FROM (SELECT chapter_id, assignment_id FROM assignment_chapter WHERE id IN (".$assignment_chapters_id.")) AS A LEFT JOIN (SELECT rules.id, rules.chapter_id FROM rules) AS B ON A.chapter_id = B.chapter_id) AS E LEFT JOIN (SELECT C.id, D.uname FROM (SELECT id, user_id FROM assignment WHERE id IN (SELECT assignment_id FROM assignment_chapter WHERE id IN (".$assignment_chapters_id."))) AS C LEFT JOIN (SELECT id, uname FROM users) AS D ON C.user_id = D.id) AS F ON E.assignment_id =F.id) AS G INNER JOIN (SELECT assignment_id, rule_id FROM assessment_rules WHERE assignment_id IN (SELECT assignment_id FROM assignment_chapter WHERE id IN (".$assignment_chapters_id."))) AS H ON G.id = H.rule_id and H.assignment_id=G.assignment_id") or error($PN.'20');
$result2 = mysql_query("SELECT G.chapter_id, G.rule_number, G.title, G.uname, H.id, H.PassOrFail, H.comment, H.last_modified FROM (SELECT E.assignment_id, E.id, E.chapter_id, E.rule_number, E.title, F.uname FROM (SELECT A.assignment_id, B.id, B.chapter_id, B.rule_number, B.title FROM (SELECT chapter_id, assignment_id FROM assignment_chapter WHERE id IN (".$assignment_chapters_id.")) AS A LEFT JOIN (SELECT rules.id, rules.chapter_id, rules.rule_number, rules.title FROM rules) AS B ON A.chapter_id = B.chapter_id) AS E LEFT JOIN (SELECT C.id, D.uname FROM (SELECT id, user_id FROM assignment WHERE id IN (SELECT assignment_id FROM assignment_chapter WHERE id IN (".$assignment_chapters_id."))) AS C LEFT JOIN (SELECT id, uname FROM users) AS D ON C.user_id = D.id) AS F ON E.assignment_id =F.id) AS G INNER JOIN (SELECT id, assignment_id, rule_id, PassOrFail, comment, last_modified FROM assessment_rules WHERE assignment_id IN (SELECT assignment_id FROM assignment_chapter WHERE id IN (".$assignment_chapters_id."))) AS H ON G.id = H.rule_id and H.assignment_id=G.assignment_id ORDER BY ".$Sorting." LIMIT ".$StartIndex.",".$PageSize.";") or error($PN.'21');
$row = mysql_fetch_array($result);
$recordCount = $row['RecordCount'];
$rows = array();
while($row = mysql_fetch_array($result2))
{
$rows[] = $row;
}
$response = array();
$response['Result'] = "OK";
$response['TotalRecordCount'] = $recordCount;
$response['Records'] = $rows;
print json_encode($response);
@mysql_close();
?>