/
lua_output_data_phpRaidViewer.php
299 lines (262 loc) · 12.7 KB
/
lua_output_data_phpRaidViewer.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
<?php
/***************************************************************************
* lua_output_data.php
* -------------------
* begin : Saturday, Jan 16, 2005
* copyright : (C) 2007-2010 Douglas Wagner
* email : douglasw@wagnerweb.org
*
***************************************************************************/
/***************************************************************************
*
* WoW Raid Manager - Raid Management Software for World of Warcraft
* Copyright (C) 2007-2008 Douglas Wagner
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
****************************************************************************/
function GetClassIdByClassName($class)
{
global $phprlang, $db_raid, $phpraid_config, $wrm_global_classes;
foreach ($wrm_global_classes as $global_class)
{
if ($class == $global_class['class_id'])
{
return $global_class['class_index'];
}
}
}
function GetClassNameByClassId($id)
{
global $phprlang, $db_raid, $phpraid_config, $wrm_global_classes;
if ($id == 0)
return "queue";
if ($id == 10)
return "skip";
foreach ($wrm_global_classes as $global_class)
{
if ($id == $global_class['class_index'])
{
$class = $global_class['lang_index'] . "s";
return $class;
}
}
}
function output_macro_drafted($raid_id)
{
global $db_raid, $text, $phpraid_config;
$sql = sprintf("SELECT * FROM " . $phpraid_config['db_prefix'] . "signups WHERE raid_id=%s AND queue='0' AND cancel='0'",quote_smart($raid_id));
$result = $db_raid->sql_query($sql) or print_error($sql, $db_raid->sql_error(), 1);
while($data = $db_raid->sql_fetchrow($result, true))
{
$sql = sprintf("SELECT * FROM " . $phpraid_config['db_prefix'] . "chars WHERE char_id=%s",quote_smart($data['char_id']));
$result2 = $db_raid->sql_query($sql) or print_error($sql, $db_raid->sql_error(), 1);
$data2 = $db_raid->sql_fetchrow($result2, true);
$data2['name'] = ucfirst(strtolower_wrap($data2['name'], "UTF-8"));
$drafted_text .= "/i {$data2['name']}\n";
}
return $drafted_text;
}
function output_macro_queued($raid_id)
{
global $db_raid, $text, $phpraid_config;
$sql = sprintf("SELECT * FROM " . $phpraid_config['db_prefix'] . "signups WHERE raid_id=%s AND queue='1' AND cancel='0'",quote_smart($raid_id));
$result = $db_raid->sql_query($sql) or print_error($sql, $db_raid->sql_error(), 1);
while($data = $db_raid->sql_fetchrow($result, true))
{
$sql = sprintf("SELECT * FROM " . $phpraid_config['db_prefix'] . "chars WHERE char_id= %s", quote_smart($data['char_id']));
$result2 = $db_raid->sql_query($sql) or print_error($sql, $db_raid->sql_error(), 1);
$data2 = $db_raid->sql_fetchrow($result2, true);
$data2['name'] = ucfirst(strtolower_wrap($data2['name'], "UTF-8"));
$queued_text .= "/i {$data2['name']}\n";
}
return $queued_text;
}
//Modified by Flintman of Hellscream
function output_lua_prv()
{
global $db_raid, $text, $phpraid_config, $wrm_global_classes;
$format=$phpraid_config['lua_output_format'];
$raid_id=scrub_input($_GET['raid_id']);
$lua_version = "250";
// Get the total number of classes, this is max class_index from the classes table.
// This will come in handy later when we're creating the LUA output.
$sql = "SELECT max(class_index) as max_class_index FROM ".$phpraid_config['db_prefix']."classes";
$max_class_query = $db_raid->sql_query($sql) or print_error($sql, $db_raid->sql_error(), 1);
$max_class_records = $db_raid->sql_fetchrow($max_class_query, true);
$max_class_index = $max_class_records['max_class_index'];
$text .= "<b>Beginning LUA output</b><br>";
// open/create file
$file = fopen('cache/raid_lua/phpRaid_Data.lua','w');
if ($file == FALSE)
$failed_to_open=TRUE;
// sql query
$sql_where = 'old=0';
if (isset($raid_id) && is_numeric($raid_id))
{
$text .= "<a href=\"lua_output.php\">Output all open raids</a><br><br>";
$sql_where = "raid_id=".quote_smart($raid_id);
}
$sql = "SELECT * FROM " . $phpraid_config['db_prefix'] . "raids WHERE ".$sql_where." ORDER BY invite_time ASC";
$raids_result = $db_raid->sql_query($sql) or print_error($sql, $db_raid->sql_error(), 1);
// base output
$lua_output = "phpRaid_Data = {\n";
$lua_output .= "\t[\"lua_version\"] = \"{$lua_version}\",\n";
// Pulls roles from WRM
$sql = "SELECT * FROM " . $phpraid_config['db_prefix'] . "roles";
$role_result = $db_raid->sql_query($sql) or print_error($sql, mysql_error(), 1);
while($role_data = $db_raid->sql_fetchrow($role_result, true))
{
$lua_output .= "\t[\"".$role_data['role_id']."\"] = \"{$role_data['role_name']}\",\n";
}
$lua_output .= "\t[\"role_count\"] = \"".$db_raid->sql_numrows($role_data)."\",\n";
$lua_output .= "\t[\"raid_count\"] = \"".$db_raid->sql_numrows($raids_result)."\",\n";
$lua_output .= "\t[\"raids\"] = {\n";
// parse result
$count = 0;
while($raid_data = $db_raid->sql_fetchrow($raids_result, true))
{
$location_data=addslashes($raid_data['location']);
$description_data=linebreak_to_bslash_n(addslashes($raid_data['description']));
$lua_output .= "\t\t[{$count}] = {\n";
$lua_output .= "\t\t\t[\"location\"] = \"$location_data\",\n";
$lua_output .= "\t\t\t[\"date\"] = \"" . new_date($phpraid_config['date_format'],$raid_data['invite_time'],$phpraid_config['timezone'] + $phpraid_config['dst']) . "\",\n";
$lua_output .= "\t\t\t[\"invite_time\"] = \"" . new_date("Hi",$raid_data['invite_time'],$phpraid_config['timezone'] + $phpraid_config['dst']) . "\",\n";
$lua_output .= "\t\t\t[\"start_time\"] = \"" . new_date("Hi",$raid_data['start_time'],$phpraid_config['timezone'] + $phpraid_config['dst']) . "\",\n";
if ($format == "1")
{
$lua_output .= "\t\t\t[\"event_type\"] = \"" . $raid_data['event_type'] . "\",\n";
$lua_output .= "\t\t\t[\"description\"] = \"$description_data\",\n";
}
// sql string for signups
$sql = sprintf("SELECT ".$phpraid_config['db_prefix']."signups.comments AS comment,
".$phpraid_config['db_prefix']."signups.selected_spec AS selected_spec,
".$phpraid_config['db_prefix']."signups.timestamp AS timestamp,
".$phpraid_config['db_prefix']."chars.name AS name,
".$phpraid_config['db_prefix']."chars.lvl AS lvl,
".$phpraid_config['db_prefix']."chars.race AS race,
".$phpraid_config['db_prefix']."chars.class AS class
FROM ".$phpraid_config['db_prefix']."signups
LEFT JOIN ".$phpraid_config['db_prefix']."chars ON
".$phpraid_config['db_prefix']."chars.char_id = ".$phpraid_config['db_prefix']."signups.char_id
WHERE ".$phpraid_config['db_prefix']."signups.raid_id = %s
AND ".$phpraid_config['db_prefix']."signups.cancel = 0
AND ".$phpraid_config['db_prefix']."signups.queue = ", quote_smart($raid_data['raid_id']));
// get data signed up
$order_by = '';
$signups = array();
if ($phpraid_config['lua_output_sort_signups'] == 1)
$order_by = 'ORDER BY '.$phpraid_config['db_prefix'].'chars.name ASC';
elseif ($phpraid_config['lua_output_sort_signups'] == 2)
$order_by = 'ORDER BY '.$phpraid_config['db_prefix'].'signups.timestamp ASC';
$sql1 = $sql."0 ".$order_by.";";
$signup_result = $db_raid->sql_query($sql1) or print_error($sql1, $db_raid->sql_error(), 1);
while($signup = $db_raid->sql_fetchrow($signup_result, true))
{
//Gets Role id
$sql4 = "SELECT * FROM " . $phpraid_config['db_prefix'] . "class_role WHERE subclass='".$signup['selected_spec']."' AND class_id ='".$signup['class']."'";
$role_result = $db_raid->sql_query($sql4) or print_error($sql4, mysql_error(), 1);
$role_info = $db_raid->sql_fetchrow($role_result, true);
$role_id = strlen($role_info['role_id'])-1;
array_push($signups, array(
'name' => ucfirst(strtolower_wrap($signup['name'], "UTF-8")),
'level' => $signup['lvl'],
'race' => $signup['race'],
'class' => $signup['class'],
'comment' => strip_linebreaks(addslashes($signup['comment'])),
'role' => $role_id,
'timestamp' => new_date($phpraid_config['date_format'],$signup['timestamp'],$phpraid_config['timezone'] + $phpraid_config['dst']) . ' - ' . new_date($phpraid_config['time_format'],$signup['timestamp'],$phpraid_config['timezone'] + $phpraid_config['dst']),
));
}
// get data queue
$order_by = '';
$queue = array();
if ($phpraid_config['lua_output_sort_queue'] == 1)
$order_by = 'ORDER BY '.$phpraid_config['db_prefix'].'chars.name ASC';
elseif ($phpraid_config['lua_output_sort_queue'] == 2)
$order_by = 'ORDER BY '.$phpraid_config['db_prefix'].'signups.timestamp ASC';
elseif ($phpraid_config['lua_output_sort_queue'] == 3)
$order_by = 'ORDER BY '.$phpraid_config['db_prefix'].'chars.class ASC';
$sql1 = $sql."1 ".$order_by.";";
$signup_result = $db_raid->sql_query($sql1) or print_error($sql1, $db_raid->sql_error(), 1);
while($signup = $db_raid->sql_fetchrow($signup_result, true))
{
//Gets Role id
$sql4 = "SELECT * FROM " . $phpraid_config['db_prefix'] . "class_role WHERE subclass='".$signup['selected_spec']."' AND class_id ='".$signup['class']."'";
$role_result = $db_raid->sql_query($sql4) or print_error($sql4, mysql_error(), 1);
$role_info = $db_raid->sql_fetchrow($role_result, true);
$role_id = strlen($role_info['role_id'])-1;
array_push($queue, array(
'name' => ucfirst(strtolower_wrap($signup['name'], "UTF-8")),
'level' => $signup['lvl'],
'race' => $signup['race'],
'class' => $signup['class'],
'comment' => strip_linebreaks(addslashes($signup['comment'])),
'role' => $role_id,
'timestamp' => new_date($phpraid_config['date_format'],$signup['timestamp'],$phpraid_config['timezone'] + $phpraid_config['dst']) . ' - ' . new_date($phpraid_config['time_format'],$signup['timestamp'],$phpraid_config['timezone'] + $phpraid_config['dst']),
));
}
// begin - add data to lua output
for($i=0; $i<=$max_class_index; $i++)
{
$class = GetClassNameByClassId($i);
if ($class != "skip")
$lua_signups[$i] = "\t\t\t[\"".$class."\"] = {\n";
}
// init counter vars
$cnt[0] = 0;
foreach ($wrm_global_classes as $global_class)
$cnt[$global_class['class_index']] = 0;
foreach($queue as $char)
{
$lua_signups[0] .= "\t\t\t\t[{$cnt[0]}] = {\n";
$lua_signups[0] .= "\t\t\t\t\t[\"name\"] = \"{$char['name']}\",\n";
$lua_signups[0] .= "\t\t\t\t\t[\"level\"] = \"{$char['level']}\",\n";
$lua_signups[0] .= "\t\t\t\t\t[\"class\"] = \"".$char['class']."\",\n";
$lua_signups[0] .= "\t\t\t\t\t[\"race\"] = \"{$char['race']}\",\n";
$lua_signups[0] .= "\t\t\t\t\t[\"comment\"] = \"{$char['comment']}\",\n";
$lua_signups[0] .= "\t\t\t\t\t[\"timestamp\"] = \"{$char['timestamp']}\",\n";
$lua_signups[0] .= "\t\t\t\t\t[\"role_id\"] = \"{$char['role']}\",\n";
$lua_signups[0] .= "\t\t\t\t},\n";
$cnt[0]++;
}
foreach($signups as $char)
{
$class_id = GetClassIdByClassName($char['class']);
$lua_signups[$class_id] .= "\t\t\t\t[{$cnt[$class_id]}] = {\n";
$lua_signups[$class_id] .= "\t\t\t\t\t[\"name\"] = \"{$char['name']}\",\n";
$lua_signups[$class_id] .= "\t\t\t\t\t[\"level\"] = \"{$char['level']}\",\n";
$lua_signups[$class_id] .= "\t\t\t\t\t[\"class\"] = \"".$char['class']."\",\n";
$lua_signups[$class_id] .= "\t\t\t\t\t[\"race\"] = \"{$char['race']}\",\n";
$lua_signups[$class_id] .= "\t\t\t\t\t[\"comment\"] = \"{$char['comment']}\",\n";
$lua_signups[$class_id] .= "\t\t\t\t\t[\"timestamp\"] = \"{$char['timestamp']}\",\n";
$lua_signups[$class_id] .= "\t\t\t\t\t[\"role_id\"] = \"{$char['role']}\",\n";
$lua_signups[$class_id] .= "\t\t\t\t},\n";
$cnt[$class_id]++;
}
// add class counts
$lua_output .= "\t\t\t[\"queue_count\"] = \"".$cnt[0]."\",\n";
foreach ($wrm_global_classes as $global_class)
$lua_output .= "\t\t\t[\"".$global_class['lang_index']."s_count\"] = \"".$cnt[$global_class['class_index']]."\",\n";
for($i=0; $i<=$max_class_index; $i++)
if ($i != 10) // Class ID Number 10 does not exist at this point.
$lua_output .= $lua_signups[$i] . "\t\t\t},\n";
$lua_output .= "\t\t},\n";
$count++;
}
$lua_output .= "\t}\n}";
// end - add data to lua output
return ($lua_output);
}
?>