-
Notifications
You must be signed in to change notification settings - Fork 2
/
deal_problem_tag.php
48 lines (44 loc) · 1.8 KB
/
deal_problem_tag.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
<?php
include_once("conn.php");
$pid=convert_str($_POST["tagpid"]);
$tagid=convert_str($_POST["utags"]);
$weight=10;
if (!db_user_match($nowuser,$nowpass)) {
echo "Please Login.";
die();
}
if (db_user_isroot($nowuser)) {
$num=1;
$force=convert_str($_POST["force"]);
$weight=intval(convert_str($_POST["weight"]));
}
else $num=@mysql_num_rows(mysql_query("select runid from status where username='$nowuser' and pid='$pid' and result='Accepted' limit 0,1"));
if ($num==0) {
echo "You haven't solved this problem.";
die();
}
$num=@mysql_num_rows(mysql_query("select id from category where id='$tagid' limit 0,1"));
if ($tagid==""||$num==0) {
echo "No such type.";
die();
}
if ($force!=1) {
$num=@mysql_num_rows(mysql_query("select id from usertag where username='$nowuser' and pid='$pid' and catid='$tagid' limit 0,1"));
if ($num!=0) {
echo "You have already tagged this type or one of its sub-types.";
die();
}
}
function tagit($pid,$tagid,$weight) {
global $force,$nowuser;
if ($force!=1) mysql_query("insert into usertag set username='$nowuser', pid='$pid', catid='$tagid'");
if (mysql_num_rows(mysql_query("select pcid from problem_category where pid='$pid' and catid='$tagid'"))==0) {
mysql_query("insert into problem_category set pid='$pid', catid='$tagid', weight='$weight'");
}
else mysql_query("update problem_category set weight=weight+$weight where pid='$pid' and catid='$tagid'");
list($tagid)=mysql_fetch_array(mysql_query("select parent from category where id='$tagid'"));
if ($tagid>0) tagit($pid,$tagid,0);
}
tagit($pid,$tagid,$weight);
echo "Tag success!";
?>