-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprint.php
46 lines (38 loc) · 1.21 KB
/
print.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
<?php
include_once('../../config.php');
$submitid = optional_param('print_submit_id', 0, PARAM_INT);
$submit = get_record('programming_submits', 'id', $submitid);
if ($submit->userid != $USER->id) {
exit(0);
}
$userfullname = fullname($USER);
$d = $CFG->dataroot.'/temp/programming';
if (!is_dir($d)) {
if (file_exists($d)) {
unlink($d);
}
mkdir($d);
}
$srcname = tempnam($d, 'pp');
$destname = tempnam($d, 'pp');
$f = fopen($srcname, 'w');
fwrite($f, $submit->code);
fclose($f);
putenv('LC_ALL=en_US.UTF-8');
system("/usr/bin/u2ps -o \"$destname\" -t \"$userfullname\" --gpfamily=\"Monospace\" \"$srcname\" 2>/dev/null");
$destprt = False;
if (address_in_subnet(getremoteaddr(), '10.1.10.0/23')) {
$destprt = 'cc2';
}
else if (address_in_subnet(getremoteaddr(), '10.1.111.0/23')) {
$destprt = 'sym1';
}
if ($destprt) {
//system("/usr/bin/lp -d $destprt -h 192.168.104.10:631 \"$destname\"");
echo get_string('printfinished', 'programming');
} else {
echo get_string('printnotallow', 'programming');
}
unlink($srcname);
unlink($destname);
?>