-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoperations.php
257 lines (216 loc) · 8.97 KB
/
operations.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
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
247
248
249
250
251
252
253
254
255
256
257
<?php
/*
* Copyright (C) 2011 Ryan Holmes
* <http://www.gnu.org/licenses/agpl.html>
*/
require '_.php';
$Page->header('Operation Info');
if (isset($_SESSION['opID'])) {
// Member submit
// This doesn't use anything from the Form class, such as validation, for various reasons.
// Mainly because it's a waste of time for an all-checkbox form (which doesn't need validating)
// and for program flow reasons. Maybe later?
if(filter_has_var(INPUT_POST, 'submitMembers')) {
if ($User->charID != $DB->q1("SELECT charID FROM `operations` WHERE opID = ?", array($_SESSION['opID']))){
$Page->errorfooter('You are not the owner of this operation; you cannot add or remove members from it'); }
$members = filter_var_array($_POST['members'], FILTER_VALIDATE_INT);
try{
if (!count($members)) {
throw new InvalidInput('No data submitted.'); }
$DB->e("INSERT INTO `groups` (`groupID`, `opID`) VALUES (?, ?)", null, $_SESSION['opID']);
$groupID = $DB->lastInsertID();
foreach ($members AS $id => $value) {
$DB->e("INSERT INTO `participants` (`charID`, `groupID`) VALUES (?, ?)", $id, $groupID); }
}
catch (InvalidInput $e) {
echo "
<p class='error'><strong>Error:</strong> </span>".$e->getMessage()."</p>\n";
}
}
// Pull all the groups for the selected OP
$groups = $DB->qa("
SELECT *, GROUP_CONCAT(name ORDER BY name SEPARATOR ', ') AS members
FROM `groups` NATURAL JOIN `participants` NATURAL JOIN `memberList`
WHERE opID = ?
GROUP BY groupID", array($_SESSION['opID']));
if (!count($groups)) {
echo "<div class='note'><strong>Notice:</strong> No participants have been added to this operation yet.</div>"; }
else {
echo "<div id='groups'><h2>Groups</h2><dl>";
for ($i=0, $l = count($groups); $i<$l; $i++) {
echo "<dt>Group ".($i+1).":</dt><dd>".$groups[$i]['members']."</dd>";
}
echo "</dl></div><span class='clear' /><!-- --></span>";
}
if ($User->charID == $DB->q1("SELECT charID FROM `operations` WHERE opID = ?", array($_SESSION['opID']))){
echo "<div id='members'><h2>Add/Remove Members</h2>";
$lastGroup = array_pop($groups);
$selected = array_flip(explode(', ', $lastGroup['members']));
$form = new Form('memberForm', 'Add/Remove Members', $_SERVER['PHP_SELF'], 'post');
$members = $DB->qa("SELECT * FROM `memberList` ORDER BY name ASC", array());
foreach ($members AS $member){
$form->add_checkbox("members", $member['name'], null, (array_key_exists($member['name'], $selected) ? true : false), $member['charID']); }
$form->add_submit('submitMembers', 'Submit');
$form->display_form();
?>
<script>
$(document).ready(function(){
$("#memberForm input").parent().append('<small></small>');
$("#memberForm input:checked").addClass("waschecked").next('small').html('KEEP').closest('dt').addClass('keep');
$("#memberForm input").change(function() {
$(this);
if ($(this).is(":checked") && $(this).hasClass("waschecked")) {
$(this).next('small').html('KEEP').closest('dt').toggleClass('remove keep'); }
else if (($(this).is(":checked") !== true && $(this).hasClass("waschecked"))){
$(this).next('small').html('REM').closest('dt').toggleClass('keep remove'); }
else if (($(this).is(":checked") && $(this).hasClass("waschecked") === false)){
$(this).next('small').html('ADD').closest('dt').toggleClass('add'); }
else if (($(this).is(":checked") !== true && $(this).hasClass("waschecked") === false)){
$(this).next('small').html('').closest('dt').removeClass('add'); }
});
});
</script>
<?php
echo "
</div>
<div id='endOp'>
<h2>End Operation</h2>
<p>Use this if your operation has completed. This will shut off the ability to add more loot and/or groups to the operation, and renders the operation eligable for loot sales. If you have not added any groups, or no loot has been submitted, the operation will be deleted from the system.</p>
<form action='".$_SERVER['PHP_SELF']."' method='post'>
<label for='confirmEnd_'><input id='confirmEnd_' type='checkbox' name='confirmEnd' value='1' /> Confirm End</label>
<button type='submit' name='endOp' value='".$_SESSION['opID']."'>End Op</button>
</form>
</div>
<div id='transferOwnership'>
<h2>Transfer Ownership</h2>
<p>You can transfer ownership to another corpmate if you are planning on leaving the operation for whatever reason. This will allow the new owner to continue adding and removing members from the operation, along with whatever else needs to be done.</p>
<form action='".$_SERVER['PHP_SELF']."' method='post'>
<select name='transfer' size='1'>\n";
foreach ($members AS $member) {
echo "
<option value='".
$member['charID']."'".
($member['charID'] == $User->charID ? " selected='selected'" : null).
">".$member['name']."</option>"; }
echo "
</select>
<button type='submit' name='transferOp'>Transfer Op</button>
</form>
</div>
";
}
echo "
<div id='salvageInfo'>
<h2>Salvager Info</h2>
<p>Are you this operation's salvager? Do you control the loot? Are you ready to stow it away in the corp hanger? If so, please head over to the <a href='lootRecord.php'>Loot Record</a> page whenever you're ready to drop it off.</p>
</div>\n";
$loots = $DB->qa("
SELECT invTypes.typeName, marketData.medianBuy, SUM(amount) AS total FROM lootData
NATURAL JOIN groups
NATURAL JOIN operations
INNER JOIN invTypes ON (lootData.typeID = invTypes.typeID)
INNER JOIN marketData ON (lootData.typeID = marketData.typeID)
WHERE opID = ?
GROUP BY lootData.typeID", array($_SESSION['opID']));
echo "
<div id='lootInfo'>
<h2>Recorded Loot</h2>
<p>Below is the loot that has been recorded for the entire operation (groups not taken into account), along with the estimated profit based on the median buy prices in Jita.</p>
<table>
<tr><th>Loot</th><th>Amount</th><th>Profit</th></tr>";
$total = 0;
foreach ($loots AS $loot) {
$profit = ((float)$loot['total']*(float)$loot['medianBuy']);
$total = $total + (float)$profit;
echo "
<tr><td>".$loot['typeName']."</td><td>".$loot['total']."</td><td>".number_format($profit)."</td></tr>";
}
echo "
<tr><td colspan='3' style='text-align: right;'>Total: ".number_format($total)."</td></tr></table>
</div>\n";
$Page->footer();
}
else{
$form = new Form ('createOp', "Create Operation", $_SERVER['PHP_SELF'], 'post');
$form->add_text('title', 'Title', false, 25, 30, 5, "30 chars max");
$form->add_textarea('description', 'Description', false, 40, 3, 4000, null, null);
$form->add_submit('submitOp', 'Submit');
echo "
<div id='opCreate'>
<span class='top'><!-- --></span>
<h2>Create Operation</h2>\n";
if ($form->check_fields_exist()) {
$form->update_values_from_post();
try {
if (!$form->validate()) {
throw new InvalidInput(); }
$DB->e("
INSERT INTO `operations` (`opID`, `charID`, `title`, `description`, `timeStart`)
VALUES (?, ?, ?, ?, ?)",
null,
$User->charID,
filter_input(INPUT_POST, 'title', FILTER_SANITIZE_SPECIAL_CHARS),
filter_input(INPUT_POST, 'description', FILTER_SANITIZE_SPECIAL_CHARS),
time()
);
$_SESSION['opID'] = $DB->lastInsertID();
// I don't like putting a redirect header here.
// look at rearraging the page's logic
header("Location: ".$_SERVER['PHP_SELF']);
}
catch (InvalidInput $e) {
echo '<p class="error">There are errors in your form!<br />';
foreach ($form->errors as $id => $errors) {
echo implode('<br />', $errors). '<br />';
}
echo '</p>'."\n\n";
}
}
$form->display_form();
echo "
<span class='bottom'><!-- --></span>
</div>
<div id='crntOps'>
<h2>Current Operations</h2>
<table>
<form action='".$_SERVER['PHP_SELF']."' method='post'>
<tr><th>Title</th><th>Owner</th><th>Start</th><th>Select</th></tr>\n";
$operations = $DB->qa("SELECT op.*, member.name FROM `operations` AS op INNER JOIN memberList member ON (member.charID = op.charID) WHERE op.timeEnd IS NULL ", array());
foreach ($operations AS $operation){
echo "
<tr>
<td>".(strlen($operation['title']) > 20 ? substr($operation['title'],0,(20 -3)).'...' : $operation['title'])."</td>
<td>$operation[name]</td>
<td>".date("m/d H:i", $operation['timeStart'])."</td>
<td><button type='submit' name='selectOpID' value='".$operation['opID']."'>Select</button></td>
</tr>\n";
}
echo "
</form>
</table>
</div>
<div id='lastOps'>
<h2>Last 10 Operations</h2>\n";
$last = $DB->qa("SELECT * FROM `operations` NATURAL JOIN memberList NATURAL LEFT JOIN op2sale NATURAL LEFT JOIN saleHistory ORDER BY timeStart DESC LIMIT 0, 10", array());
echo "
<table>
<tr>
<th>ID</th><th>Title</th><th>Owner</th><th>Ended?</th><th>Sold?</th><th>Payed?</th>
</tr>\n";
foreach($last AS $op) {
echo "
<tr>
<td>$op[opID]</td>
<td>$op[title]</td>
<td>$op[name]</td>
<td>".($op['timeEnd'] !== null ? 'Yes' : 'No')."</td>
<td>".($op['saleTime'] !== null ? 'Yes' : 'No')."</td>
<td>".($op['payedTime'] !== null ? 'Yes' : 'No')."</td>
</tr>\n";
}
echo "
</table>
</div>\n";
$Page->footer();
}
?>