-
Notifications
You must be signed in to change notification settings - Fork 0
/
modify_audit.php
81 lines (62 loc) · 2.43 KB
/
modify_audit.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
<?php
require_once('settings.php');
require_once('moodle.inc');
if (isloggedin() && $USER->username != 'guest') {
$moodle_id = $USER->id;
} else {
die("Not logged in");
}
$link = mysql_connect($db_server,$db_username,$db_password);
if (! mysql_select_db($db_database)) {
die(mysql_error());
}
if (preg_match('/^\d+$/', $_POST['collection_id'])) {
$query = 'SELECT collection_id, institution_id FROM collection WHERE collection_id=' . $_POST['collection_id'] . '';
$result = mysql_query($query);
if (!$result) {
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query;
die($message);
}
if ($row = mysql_fetch_assoc($result)) {
$collection_id = $row['collection_id'];
$institution_id = $row['institution_id'];
} else {
die('Invalid collection: collection_id not found');
}
} else {
die('Invalid collection: No collection_id');
}
$query = 'SELECT visible_priv FROM institution LEFT JOIN institution_auth ON institution_auth.institution_id = institution.institution_id WHERE institution_auth.moodle_id = ' . $moodle_id;
$result = mysql_query($query);
if (!$result) {
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query;
die($message);
}
if (! $row = mysql_fetch_assoc($result)) die("No auth for institution");
if (array_key_exists('visible',$_POST)) {
if (! $row['visible_priv']) die("Not allowed to change visibility");
$query = sprintf('UPDATE collection SET visible=%d WHERE collection_id=%d',$_POST['visible']=='1',$collection_id);
$result = mysql_query($query);
if (!$result) {
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query;
die($message);
}
}
if (array_key_exists('is_audit',$_POST)) {
if ($_POST['is_audit'] == '1') {
$query = sprintf('UPDATE collection SET allow_report=0, allow_user_lock=1, allow_multiple_sessions=0, is_audit=1 WHERE collection_id=%d',$collection_id);
} else {
$query = sprintf('UPDATE collection SET allow_report=1, allow_user_lock=0, allow_multiple_sessions=1, is_audit=0 WHERE collection_id=%d',$collection_id);
}
$result = mysql_query($query);
if (!$result) {
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query;
die($message);
}
}
header("Location: " . $sqa_www_root . "/admin_audits.php");
?>