-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathops_assign_group.php
300 lines (257 loc) · 11.6 KB
/
ops_assign_group.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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
<?php require_once('access_and_open.php'); require_once('secure.php'); ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Op Session Groups</title>
</head>
<body>
<h1>Op Session Groups</h1>
<a href="index.php">Back to main page</a><p/>
<?php
include_once('mysql2i.class.php'); // migration step
require_once('ops_assign_common.php');
// parse out arguments
parse_str($_SERVER["QUERY_STRING"], $args);
// first, see if there's a "?cy=" in the arguments
if (! array_key_exists("cy", $args)) {
echo "This is the starting page for op session assignments.<p/>";
echo "It's also where you group attendees together when they want the same assignment.<p/>";
echo "Please provide a cycle name and press start start. If the name exists, we'll load that, otherwise we'll create it.";
echo '<form method="get" action="ops_assign_group.php">
Cycle Name: <input name="cy"></textarea>
<button type="submit">Start</button>
</form>
';
// display existing cycles & number of assignments)
echo '<h3>Existing cycles</h3><table><tr><th>Cycle Name</th><th>N Assigned</th></tr>';
global $opts, $event_tools_db_prefix, $event_tools_href_add_on;
mysql_connect($opts['hn'],$opts['un'],$opts['pw']);
@mysql_select_db($opts['db']) or die( "Unable to select database");
$query="
SELECT opsreq_group_cycle_name, SUM(status)
FROM ".$event_tools_db_prefix."eventtools_ops_group_session_assignments
GROUP BY opsreq_group_cycle_name
ORDER BY opsreq_group_cycle_name
;
";
$result=mysql_query($query);
$num = mysql_numrows($result);
for ($i = 0; $i < $num; $i++) {
echo '<tr><td><a href="?cy='.mysql_result($result,$i,"opsreq_group_cycle_name").'">'.mysql_result($result,$i,"opsreq_group_cycle_name").'</a></td><td>'.mysql_result($result,$i,1).'</td></tr>';
}
echo '</table>';
return;
} else {
$cycle = $args["cy"];
}
// here, the cycle name exists,
echo '<h2>Cycle: '.$cycle.'</h2>';
// Try to load it
global $opts, $event_tools_db_prefix, $event_tools_href_add_on;
mysql_connect($opts['hn'],$opts['un'],$opts['pw']);
@mysql_select_db($opts['db']) or die( "Unable to select database");
$query="
SELECT *
FROM ".$event_tools_db_prefix."eventtools_opsreq_group
WHERE opsreq_group_cycle_name = '".$cycle."'
;
";
$result=mysql_query($query);
$num = mysql_numrows($result);
if ($num == 0) {
// no rows found, load
echo "(Creating ...)<p/>";
// read the original request database
$query="
SELECT *
FROM ".$event_tools_db_prefix."eventtools_opsession_req
;
";
$reqs=mysql_query($query);
$num = mysql_numrows($reqs);
// insert those
insert_multiple_ops_request_structure($cycle, $reqs);
}
echo '<form method="get" action="ops_assign_set.php?cy='.$cycle.'">';
echo '<input type="hidden" name="cy" value="'.$cycle.'">';
echo '<button type="submit">Continue to assignments</button>';
echo '</form>';
echo "<h2>Setting Groups</h2>";
echo "(Loading ...)<p/>";
// Are there any merge requests?
$merges = array_keys($args, "merge");
if (count($merges) > 0) {
// yes, check for whether they agree
echo 'Starting to group '.count($merges).' entries';
echo '<br/>';
// merges[] are group keys; see if the requests match up
// there's always at least merges[0]
$query = "SELECT * FROM (
".$event_tools_db_prefix."eventtools_opsreq_group_req_link
JOIN
".$event_tools_db_prefix."eventtools_opsession_req
USING (opsreq_id)
)
WHERE opsreq_group_req_link_id = '".$merges[0]."'
;
";
$matchstart=mysql_query($query);
echo '<br/>Start with <a href="edit_ops_all.php?email='.mysql_result($matchstart,0,"opsreq_person_email").'" target="_blank">'.mysql_result($matchstart,0,"opsreq_person_email").'</a><br/>';
for ($i = 1; $i < count($merges); $i ++) {
$query = "SELECT * FROM (
".$event_tools_db_prefix."eventtools_opsreq_group_req_link
JOIN
".$event_tools_db_prefix."eventtools_opsession_req
USING (opsreq_id)
)
WHERE opsreq_group_req_link_id = '".$merges[$i]."'
;
";
$matchmid=mysql_query($query);
$goodcheck = TRUE;
echo ' Checking <a href="edit_ops_all.php?email='.mysql_result($matchmid,0,"opsreq_person_email").'" target="_blank">'.mysql_result($matchmid,0,"opsreq_person_email").'</a><br/>';
for ($j = 1 ; $j <= 12 ; $j ++) {
if (mysql_result($matchmid,0,"opsreq_pri".strval($j)) != mysql_result($matchstart,0,"opsreq_pri".strval($j)) ) {
if (! array_key_exists("force", $args)) {
echo "<b>Error: Request ".strval($j)." for \"".session_title_from_query(mysql_result($matchmid,0,"opsreq_pri".strval($j)))."\" doesn't match \"".session_title_from_query(mysql_result($matchstart,0,"opsreq_pri".strval($j)))."\"</b><br/>\n";
$goodcheck = FALSE;
} else {
echo "Setting request ".strval($j)." for \"".session_title_from_query(mysql_result($matchmid,0,"opsreq_pri".strval($j)))."\" to \"".session_title_from_query(mysql_result($matchstart,0,"opsreq_pri".strval($j)))."\"<br/>\n";
// make the change
$query = "UPDATE ".$event_tools_db_prefix."eventtools_opsreq_req_status
SET ops_id='".mysql_result($matchstart,0,"opsreq_pri".strval($j))."'
WHERE opsreq_group_req_link_id = '".$merges[$i]."'
AND req_num='".$j."'
;";
mysql_query($query);
//echo '<p>'.$query.'</p>';$goodcheck = FALSE;
}
}
}
}
if ($goodcheck) {
// OK: do the merge; keys are link numbers
// create a new group
$query = "INSERT INTO ".$event_tools_db_prefix."eventtools_opsreq_group
(opsreq_group_cycle_name)
VALUES
('".$cycle."')
;";
$groups=mysql_query($query);
$id = mysql_insert_id();
// update the links
for ($i = 0; $i < count($merges); $i ++) {
$query = "UPDATE ".$event_tools_db_prefix."eventtools_opsreq_group_req_link
SET opsreq_group_id='".$id."'
WHERE opsreq_group_req_link_id = '".$merges[$i]."'
;";
mysql_query($query);
}
echo "<p>Merge complete<p>\n";
} else {
// Not OK: give an override button
echo '<form method="get" action="ops_assign_group.php?cy='.$cycle.'">';
echo "<p><b>Skipping grouping because requests don't match</b>\n";
echo '<input type="hidden" name="cy" value="'.$cycle.'">'."\n";
for ($j = 0; $j < count($merges) ; $j ++) {
echo '<input type=hidden name="'.$merges[$j].'" value="merge">'."\n";
}
echo '<input type="hidden" name="force" value="yes">'."\n";
echo '<button type="submit" name="group" value="group">Force this grouping, making all requests match first</button>'."\n";
echo '</form>';
}
}
// Create a table form with a check-box for merging
echo 'Check boxes and click "Group" at bottom to combine requests, or click the Continue to Assignments Button above.<br>';
echo '<form method="get" action="ops_assign_group.php?cy='.$cycle.'"><table border="1">'."\n";
echo '<tr><th></th><th></th><th>Name</th><th>Comment</th>'."\n";
// echo '<th>Debug G</th><th>Debug L</th></tr>'."\n";
$query="
SELECT *
FROM ".$event_tools_db_prefix."eventtools_ops_group_names
WHERE opsreq_group_cycle_name = '".$cycle."'
ORDER BY opsreq_group_id
;
";
$result=mysql_query($query);
$num = mysql_numrows($result);
$rows = array();
for ($i = 0; $i < $num; ) {
$rowstring = "";
// check for a group
for ($j = $i+1; $j < $num; $j++) {
if (mysql_result($result,$j,"opsreq_group_id") != mysql_result($result,$i,"opsreq_group_id") ) break;
}
// build row
$rowstring = $rowstring.'<tr><td>';
for ($k = $i; $k < $j; $k++) {
$rowstring = $rowstring.'<input type=CHECKBOX name="'.mysql_result($result,$k,"opsreq_group_req_link_id").'" value="merge">';
if ($k != $j-1) $rowstring = $rowstring.'<hr/>';
}
$rowstring = $rowstring.'</td><td>';
$rowstring = $rowstring.'XXXXXX'; // we'll replace that XXXXXXX with an ^ in some cases below
$rowstring = $rowstring.'</td><td>';
for ($k = $i; $k < $j; $k++) {
$rowstring = $rowstring.mysql_result($result,$k,"customers_firstname").' '.mysql_result($result,$k,"customers_lastname").' '.mysql_result($result,$k,"opsreq_person_email");
if ($k != $j-1) $rowstring = $rowstring.'<hr/>';
}
$rowstring = $rowstring.'</td>';
// and then add the comment
$rowstring = $rowstring.'<td>';
for ($k = $i; $k < $j; $k++) {
$rowstring = $rowstring.mysql_result($result,$k,"opsreq_comment");
if ($k != $j-1) $rowstring = $rowstring.'<hr/>';
}
$rowstring = $rowstring.'</td>';
// $rowstring = $rowstring.'<td>';
// for ($k = $i; $k < $j; $k++) {
// $rowstring = $rowstring.mysql_result($result,$k,"opsreq_group_id").'<br/>';
// }
// $rowstring = $rowstring.'</td><td>';
// for ($k = $i; $k < $j; $k++) {
// $rowstring = $rowstring.mysql_result($result,$k,"opsreq_group_req_link_id").'<br/>';
// }
// $rowstring = $rowstring.'</td>';
$rowstring = $rowstring.'</tr>'."\n";
// query to construct a key for this group
$query="
SELECT *
FROM (".$event_tools_db_prefix."eventtools_opsreq_group
LEFT JOIN ".$event_tools_db_prefix."eventtools_opsreq_group_req_link
ON ".$event_tools_db_prefix."eventtools_opsreq_group.opsreq_group_id = ".$event_tools_db_prefix."eventtools_opsreq_group_req_link.opsreq_group_id )
LEFT JOIN ".$event_tools_db_prefix."eventtools_opsreq_req_status
ON ".$event_tools_db_prefix."eventtools_opsreq_group_req_link.opsreq_group_req_link_id = ".$event_tools_db_prefix."eventtools_opsreq_req_status.opsreq_group_req_link_id
WHERE ".$event_tools_db_prefix."eventtools_opsreq_group.opsreq_group_id = ".mysql_result($result,$i,"opsreq_group_id")."
;
";
$sess=mysql_query($query);
$n = min(mysql_numrows($sess),12);
$key = "";
for ($k = 0; $k < $n ; $k++) {
$key=$key.mysql_result($sess,$k,"ops_id")." ";
}
$key = $key."/".mysql_result($result,$i,"opsreq_group_id");
$rows[$key] = $rowstring;
$i = $j;
}
// sort on keys and show rows
ksort($rows);
$lastkey = "";
foreach ($rows as $key => $val) {
if ($lastkey == substr($key,0,strpos($key,'/')) ) {
echo str_replace('XXXXXX','^',$val);
} else {
echo str_replace('XXXXXX','',$val);
}
$lastkey = substr($key,0,strpos($key,'/'));
}
echo '</table>';
echo '<p>';
echo "Click the button below to group all selected attendees. If the requests don't agree, you'll be prompted whether to force them all to be the same as the 1st checked attendee.<br>";
echo '<input type="hidden" name="cy" value="'.$cycle.'">';
echo '<button type="submit" name="group" value="group">Group all checked rows above</button></form>';
?>
</body>
</html>