-
Notifications
You must be signed in to change notification settings - Fork 0
/
tag_game.php
156 lines (112 loc) · 4.4 KB
/
tag_game.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?
include("connect.php");
include("functions.php");
$q_random_uids = mysql_query("SELECT uid,type FROM problems ORDER BY RAND() LIMIT 3");
while ($row = mysql_fetch_array($q_random_uids)) {
$uid_list[]=$row{'uid'};
}
?>
<h3>Tag game!</h3>
<p>Add any tags the following problems might be missing!</p>
<table width=100% cellpadding="10" cellspacing="0" border=0>
<?
// if anything is left, put it back together for the sql query
if (sizeof($uid_list) > 0) { $uid_string = implode(", ",$uid_list); }
else { echo "No UIDs specified!"; die; }
// query the problems
$q_probs = mysql_query("SELECT uid,prob,answer,type FROM problems WHERE uid IN ($uid_string) ORDER BY type, uid");
// get the tagids for every problem in the query
$q_tagids = mysql_query("SELECT probid,tagid FROM probtags WHERE probid IN ($uid_string)");
while ($row = mysql_fetch_array($q_tagids))
{
$prob_tags[$row{'probid'}][$row{'tagid'}]="";
$all_tags[$row{'tagid'}] = ""; // this will be filled with tag names later
}
// get the tag names for every tag found above
$tagid_list = "\"".implode("\",\"",array_keys($all_tags))."\"";
$q_tagnames = mysql_query("SELECT uid,tag FROM tags WHERE uid IN ($tagid_list)");
while ($row = mysql_fetch_array($q_tagnames))
{
$all_tags[$row{'uid'}] = $row{'tag'};
}
// adjoin the tagids in $prob_tags with their real names
foreach($prob_tags as $uid => $tagarray)
{
foreach($tagarray as $tagid => $blank)
{
$prob_tags[$uid][$tagid] = $all_tags[$tagid];
}
}
// construct the main array of problems
while ($row = mysql_fetch_array($q_probs))
{
$probs[$row{'type'}][$row{'uid'}]['prob'] = $row{'prob'};
$probs[$row{'type'}][$row{'uid'}]['answer'] = $row{'answer'};
$probs[$row{'type'}][$row{'uid'}]['tags'] = $prob_tags[$row{'uid'}]; // array of tagids from above
}
// get the directions for each type
$type_list = "\"".implode("\",\"",array_keys($probs))."\"";
$q_directions = mysql_query("SELECT type,directions FROM directions WHERE type IN ($type_list)");
while ($row = mysql_fetch_array($q_directions)) { $directions[$row{'type'}] = $row{'directions'}; }
// compute content cell widths
$username=$_COOKIE['username'];
$user_info=mysql_fetch_array(mysql_query("SELECT * FROM user_data WHERE username='$username'"));
$spaces = 2*(1 + $user_info['solution_pref']) + 1;
$big_space = 2*round(100/$spaces);
$small_space = round(100/$spaces);
// begin the table to display results
echo "<table width=100% cellpadding=\"10\" cellspacing=\"0\" border=\"0\">";
// loop through each type
foreach ($probs as $type => $type_probs)
{
// print a blank spacer row
echo "<tr bgcolor=white><td></td></tr>";
// print the directions row
echo "<tr bgcolor=lightblue><td colspan=6><b>".$directions[$type]."</b></td></tr>";
// loop through each problem of that type
foreach ($type_probs as $uid => $curprob)
{
// start counting to flip between colors
$count += 1;
if ($count % 2) { $rowcolor = "E1FCFC"; } else { $rowcolor = "CCFFFF"; }
// start the row
echo "<tr bgcolor = \"$rowcolor\">";
// print a blank spacer cell
echo "<td width=\"1px\" bgcolor=white> </td>";
// print add/edit buttons cell
echo "<td width=\"50px\" align=center>";
echo "<p><span id=\"button$uid\">";
sensitive_button($uid);
echo "</span>";
echo "<p><a href='add_prob_form.php?uid=$uid' title='Edit problem number $uid' ";
echo "onclick=\"return GB_showCenter('Edit problem', this.href,550,700,function () { query_last();} )\">";
echo "<img border=0 src='img/edit.png'></a>";
echo "</td>";
// print the problem
echo "<td width=$big_space%>";
echo build_prob($uid,$curprob['prob'],0);
echo "</td>";
// if solutions are enabled, print the solution
if ($user_info['solution_pref'])
{
echo "<td width=$big_space%>";
echo "<span style=\"font-size:x-small;\">Answer</span>";
echo "<p style=\"border: solid lightgray 1pt; padding:5px;\">";
echo build_prob($uid,$curprob['answer'],0,"f","a");
echo "</td>";
}
// print the tags
echo "<td width=$small_space%>";
echo "<span id=\"tagarea$uid\"><small>Tags: (<a class='xbutton' href=\"javascript:load_tag_box($uid)\">add tag</a>)</small></span><br>";
echo "<span id=\"taglist$uid\">";
echo implode(", ",$probs[$type][$uid]['tags'])."";
echo "</span></td>";
// finish the row
echo "</tr>";
}
}
// end the table of results
echo "</table>";
?>
</table>
<center><h2><a href="javascript:play_tag_game();">Play Again</a>!</h2></center>