forked from BNUACM/bnuoj-web-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
challenge_src_image_old.php
44 lines (41 loc) · 1.55 KB
/
challenge_src_image_old.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
<?php
function toimage($text,$fsize) {
$text = str_replace("\r", "", $text);
$text = str_replace("\t", " ", $text);
$lines=explode("\n",$text);
$width=0;
foreach ($lines as $line) {
$width=max($width,strlen($line)*imagefontwidth($fsize)+10);
}
$height=sizeof($lines)*imagefontheight($fsize)+10;
$im = imagecreatetruecolor($width,$height);
$bg = imagecolorallocate($im, 201, 201, 201);
imagefilledrectangle($im, 0, 0, $width, $height, $bg);
$text_color = imagecolorallocate($im, 51 , 51 , 51 );
$cnt=0;
foreach ($lines as $line) {
imagestring($im, $fsize, 5, 5+$cnt*imagefontheight($fsize), $line, $text_color);
$cnt++;
}
imagepng($im);
imagedestroy($im);
die();
}
include_once("conn.php");
$pid = convert_str($_GET['pid']);
$user = convert_str($_GET['username']);
$cid = convert_str($_GET['cid']);
header('Content-Type: image/png');
if (!db_user_match($nowuser,$nowpass)||(!db_contest_challenging($cid)&&!db_contest_passed($cid))) {
toimage("Permission Denied.",5);
}
$query="select runid,result,source from status where contest_belong='$cid' and pid='$pid' and username='$user' order by runid desc";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
if ($row[1]=="Pretest Passed"||$row[1]=="Accepted"||db_contest_passed($cid)) {
toimage($row[2],3);
}
else {
toimage("Invalid Request!",5);
}
?>