-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocessor.php
executable file
·159 lines (145 loc) · 6.28 KB
/
processor.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
157
158
159
<?php
require_once dirname(__FILE__) . '/lib/access.php';
if (!accessTest()) {
echo '<error>access violation</error>';
exit(0);
}
require_once dirname(__FILE__) . '/classes/Match.php';
require_once dirname(__FILE__) . '/classes/Stake.php';
require_once dirname(__FILE__) . '/classes/User.php';
require_once dirname(__FILE__) . '/classes/Leaderboard.php';
require_once dirname(__FILE__) . '/templates/templates.php';
switch ($_REQUEST['action']) {
case 'make_stake':
try {
$match = new Match($_REQUEST['match_id']);
$match->makeStake(userid(), $_REQUEST['score1'], $_REQUEST['score2']);
inner_menu($match, userid());
exit(0);
} catch (Exception $e) {
echo $e->getMessage();
}
break;
case 'get_stakes':
function out($title, $stakes) {
echo '<div class="span4">';
$count = count($stakes);
echo "<h6>$title ($count)</h6>";
echo '<ul class="unstyled">';
$previousStakeScore = $stakes[0];
foreach ($stakes as $stake) {
$mine = $stake->getUID() == userid();
$stakeScore = $stake->getStakeScore();
echo "<li class=\"" . ($stake->getType()) . "\" " . (strcmp($stakeScore, $previousStakeScore) != 0 ? "style=\"padding-top: 10px;" : "") . "\">" . ($mine ? "<b>" : "") . username($stake->getUID()) . ': ' . $stakeScore . (($stake->isPlayed()) ? ' (' . $stake->getScore() . ')' : '') . ($mine ? "</b>" : "") . '</li>';
$previousStakeScore = $stakeScore;
}
echo '</ul></div>';
}
function filter_and_sort($all_stakes, $type) {
$filter_result = array();
$score_popularity = array();
foreach ($all_stakes as $stake) {
if ($stake->getType() == $type) {
array_push($filter_result, $stake);
$score_popularity[$stake->getStakeScore()]++;
}
}
arsort($score_popularity);
$result = array();
foreach ($score_popularity as $score => $popularity) {
foreach ($filter_result as $index => $stake) {
if (strcmp($stake->getStakeScore(), $score) == 0) {
array_push($result, $stake);
}
}
}
return $result;
}
try {
$match = new Match($_REQUEST['match_id']);
if (!$match->isAvailableFor(userid())) {
$stakes = Stake::getByMatchId($_REQUEST['match_id']);
echo '<div class="row-fluid">';
out("{$match->getCompetitor1()->getName()} победит", filter_and_sort($stakes, Stake::WIN1));
out("ничья", filter_and_sort($stakes, Stake::DRAW));
out("{$match->getCompetitor2()->getName()} победит", filter_and_sort($stakes, Stake::WIN2));
echo '</div>';
} else {
echo 'Атата!';
}
} catch (Exception $e) {
echo $e->getMessage();
}
break;
case 'get_matches':
$matches = array();
switch ($_REQUEST['type']) {
case 'available':
$matches = Match::getAvailable();
break;
case 'active':
$matches = Match::getActive();
break;
case 'played':
$matches = Match::getPlayed(20);
break;
}
if (!empty ($matches)) {
?>
<!--<u onClick="javascript: openAllMatches(this)">Развернуть все</u>-->
<ul>
<?
foreach ($matches as $match) {
show_match($match, userid());
}
?>
</ul>
<? if ($_REQUEST['type'] == 'played'): ?>
<div class="alert alert-info">И ещё много-много матчей...</div>
<? endif; ?>
<?
} else {
echo '<div class="alert alert-info">Матчей нет</div>';
}
break;
case 'load_stakes_for_uid':
$user = new User($_REQUEST['quid']);
$stakes = $user->getPlayedStakes($_REQUEST['comp_id']);
foreach ($stakes as $stake) {
$match = new Match($stake->getMatchId());
if (!isset($_REQUEST['full'])) {
echo '<li>' . $match->getName() . ':<br/><small>Счёт: ' . $match->getScore() . '; Ставка: ' . $stake->getStakeScore() . ' ' . (($stake->getScore() > 0) ? '<b>' : '') . '(' . $stake->getScore() . ')' . (($stake->getScore() > 0) ? '</b>' : '') . '</small></li>';
} else {
show_match($match, $user->getId());
}
}
break;
case 'load_rating':
$users = User::getAllByRating($_REQUEST['comp_id']);
$leaderboard = Leaderboard::getByCompId($_REQUEST['comp_id']);
$next_li_class = "";
foreach ($users as $user) {
$cur_uid = $user['user']->getId();
$strong = $leaderboard != null && $leaderboard->hasPlayer($cur_uid);
$mark = $cur_uid == userid();
?>
<li class="<?= $next_li_class ?>">
<? if ($strong) { ?><strong><? } ?>
<? if ($mark) { ?><mark><? } ?>
<a href="#"
onClick="userClick(this, <?= $cur_uid ?>, <?= $_REQUEST['comp_id'] ?>);"><?= $user['user']->getSNnbsp() ?></a><?
if ($mark) { ?></mark><? }
if ($strong) { ?></strong><? } ?>
(<?= $user['scores'] ?>)
<? if ($user['sort_info'] != "" && $user['sort_info'] != "EQUAL") {
echo '<a class="sort_info_link" href="#a" <span class="sort_info_arrows" onclick="showAdvancedRatingInfo(' . $cur_uid . ')">' . "⏫" . '</span></a>' .
'<span class="sort_info" id="sort_info_message_' . $cur_uid . '" style="visibility: hidden">' . $user['sort_info'] . '</span>';
} ?>
<ul style="display: none;" id="stakes_user_<?= $cur_uid ?>"></ul>
</li>
<?
$next_li_class = $user['sort_info'] == "EQUAL" ? "skipped" : "";
}
break;
}
?>