-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoz2.php
More file actions
246 lines (222 loc) · 6.37 KB
/
oz2.php
File metadata and controls
246 lines (222 loc) · 6.37 KB
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
<?php session_start(); ?>
<?php
require_once("require/basic.php");
require_once("require/secure.php");
require_once("require/rplayers.php");
require_once("require/rgame.php");
// Admin only page
Secure(true);
if( isset($_REQUEST["action"]) && !is_game_started())
{
if( $_REQUEST["action"] == "Save OZ List" )
{
$ids = array();
if( isset($_REQUEST["ids"] ) ) { $ids = $_REQUEST["ids"]; }
set_oz_list( $ids );
set_alert("SUCCESS", "OZ list saved.");
}
if( $_REQUEST["action"] == "Remove from Pool" )
{
$id = $_REQUEST["id"];
remove_from_pool($id);
set_alert("SUCCESS", "Player removed from OZ Pool.");
}
}
$players = get_players();
$oz_list = get_oz_list();
$oz_pool = get_oz_pool();
$player_ids = get_ids($players);
$pool_initial = array_diff( $oz_pool, $oz_list );
$all_initial = array_diff( $player_ids, $oz_list );
page_head();?>
<div class="row">
<div class="col-md-12">
<?php if( is_game_started() ) echo "<strong>Game has been started, OZ tables are now read-only</strong>";?>
<div class="row">
<div class="col-md-4">
<h4>OZ Pool (<span id="pn"></span>)</h4>
</div>
<?php if ( !is_game_started() ) { ?>
<div class="col-md-4">
<h4>All Players (<span id="an"></span>)</h4>
</div>
<?php } ?>
<div class="col-md-4">
<h4>OZ List (<span id="ln"></span>)</h4>
</div>
</div>
<?php if( !is_game_started() ) { ?>
<div class="row">
<div class="col-md-4">
<form class="form-inline">
<div class="form-group">
<label>Add <input style="width: 40px" class="form-control" id="rand" value="0"/> random OZs</label>
<input type="button" class="btn btn-default" id="go" value="Go" />
</div>
</form>
</div>
<?php if( !is_game_started() ) { ?>
<div class="col-md-4 col-md-offset-4">
<form class="form-inline" method="post" action="" id="save">
<input type="button" class="btn btn-default" id="clear" value="Clear"/>
<?php
foreach($oz_list as $id)
{
?>
<input type="hidden" name="ids[]" value="<?php echo $id; ?>"/>
<?php
}
?>
<input class="form-control" type="submit" name="action" value="Save OZ List" id="save_button" style="display:none;" />
</form>
</div>
<?php } ?>
</div>
<?php } ?>
<div class="row">
<div id="pool" class="col-md-4">
<?php gen_player_table( $players, $ozPlayerProperties, $pool_initial, false ); ?>
</div>
<?php if( !is_game_started() ) { ?>
<div id="all" class="col-md-4">
<?php gen_player_table( $players, $namePlayerProperties, $all_initial, false ); ?>
</div>
<?php } ?>
<div id="list" class="col-md-4">
<?php gen_player_table( $players, $namePlayerProperties, $oz_list, false ); ?>
</div>
</div>
</div>
</div>
<script type="text/javascript">
var changes = false;
var started = <?php if(is_game_started()) { echo "true"; } else { echo "false"; } ?>;
var ozpool = <?php echo json_encode($oz_pool); ?>;
var ozlist = <?php echo json_encode($oz_list); ?>;
var players = <?php echo json_encode($player_ids); ?>;
function UpdateCounts()
{
$("span#pn").html(poolTable.count());
if( !started )
$("span#an").html(allTable.count());
$("span#ln").html(listTable.count());
}
function OnChange()
{
if( !changes )
{
$("input#save_button").show();
window.onbeforeunload = function()
{
return "Unsaved changes have been made to the OZ List, are you sure you want to leave?";
};
changes = true;
}
UpdateCounts();
}
function Saved()
{
window.onbeforeunload = null;
}
$("input#save_button").click(function() { Saved(); });
function AddToList(id)
{
if( listTable.addPlayer(id) )
{
$("<input type='hidden' name='ids[]'>").val(id).appendTo($("#save"));
poolTable.removePlayer(id);
allTable.removePlayer(id);
OnChange();
}
}
function RemoveFromList(id)
{
if( listTable.removePlayer(id) )
{
$("input[name='ids[]'][value=" + id + "]").remove();
if( $.inArray( id, ozpool ) > -1 )
{
poolTable.addPlayer( id );
}
allTable.addPlayer( id );
OnChange();
}
}
function ClearList()
{
var x = listTable.getPlayerIDs();
if( x.length == 0 ) return;
for( var i = 0; i < x.length; i++ )
{
$("input[name='ids[]'][value=" + x[i] + "]").remove();
if( $.inArray( x[i], ozpool ) > -1 )
{
poolTable.addPlayer( x[i] );
}
allTable.addPlayer( x[i] );
}
listTable.clear();
OnChange();
}
// load all player data
LoadPlayerData2(<?php echo json_encode( $players ); ?>);
var add_all = {};
var add_pool = {};
var remove = {};
if( !started )
{
add_pool = { "Add":{"type":"js", "func":AddToList}, "Remove from Pool":{"type":"post", "confirm":true} };
add_all = { "Add":{"type":"js", "func":AddToList} };
remove = { "Remove":{"type":"js", "func":RemoveFromList} };
}
// pool table
var poolTable = new PlayerTable2( namePlayerProperties, { }, add_pool );
poolTable.take( $("#pool"), false );
// all table
var allTable = null;
if( !started )
{
allTable = new PlayerTable2( namePlayerProperties, { }, add_all );
allTable.take( $("#all"), false );
}
// list table
var listTable = new PlayerTable2( namePlayerProperties, { }, remove );
listTable.take( $("#list"), false );
UpdateCounts();
// random OZ adding
$("input#go").click( function() {
var initial = poolTable.getPlayerIDs();
var p = [];
for ( var i = 0; i < initial.length; i++ )
{
if (poolTable.getPlayerObj(initial[i]).waiver === "1")
{
p.push(initial[i]);
}
}
var r = [];
var num = parseInt($("input#rand").val());
if( isNaN( num ) ) {
alert( "Not a number!");
return;
}
if( num > p.length ) {
alert("Not enough players in the pool!");
return;
}
for( var a = 0; a < num; a++ )
{
var x = Math.floor( Math.random()*p.length );
r.push(p[x]);
p.splice(x,1);
}
for( var a = 0; a < num; a++ )
{
AddToList( r[a] );
}
});
$("input#clear").click( ClearList );
</script>
<?php
page_foot();
?>