-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_audit.php
90 lines (67 loc) · 2.32 KB
/
create_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
82
83
84
85
86
87
88
89
<?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());
}
function parse_date3($year,$month,$day) {
if (! preg_match('/^\d+$/', $year)) { return(''); }
if (! preg_match('/^\d+$/', $month)) { return(''); }
if (! preg_match('/^\d+$/', $day)) { return(''); }
return $year . '-' . $month . '-' . $day;
}
if (preg_match('/^\d+$/', $_POST['module_id'])) {
$query = 'SELECT module_id FROM module WHERE module_id=' . $_POST['module_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)) {
$module_id = $row['module_id'];
} else {
die('Invalid module');
}
} else {
die('Invalid module: No module_id');
}
if (preg_match('/^\d+$/', $_POST['institution_id'])) {
$query = sprintf('SELECT institution_id, visible_priv FROM institution_auth WHERE moodle_id=%d AND institution_id=%d',
$moodle_id,$_POST['institution_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)) {
$institution_id = $row['institution_id'];
} else {
die('Invalid institution');
}
} else {
die('Invalid institution: No institution_id');
}
if ($_POST['scope'] == '') die("Scope cannot be empty");
$request_error = 'Request sent';
$query = sprintf('insert into collection (scope,start_date,end_date,module_id,institution_id) ' .
' values ("%s","%s","%s",%d,%d)',
mysql_real_escape_string( $_POST['scope']),
parse_date3($_POST['start_dateYYYY'],$_POST['start_dateMM'],$_POST['start_dateDD']),
parse_date3($_POST['end_dateYYYY'],$_POST['end_dateMM'],$_POST['end_dateDD']),
$module_id,$institution_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");
?>