forked from X-Genesis-Qhulut/alpha
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwow_alpha_utils.php
executable file
·2328 lines (1889 loc) · 64.1 KB
/
wow_alpha_utils.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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/*
Author: X'Genesis Qhulut <[email protected]>
Date: August 2022
See LICENSE for license details.
*/
/*
Regarding positioning:
When doing a search, which may be on text (eg. "bread") and also a field (eg. level > 5) we get a bunch
of results, which are presented in pages of QUERY_LIMIT (200) items per page.
Users can select which page they want to view, and then choose an item, ie. from the first (item 1) to the
last (item 200).
When viewing an item they can go forwards or backwards without returning to the search listing. Thus we need
to know where they are. We record, in the URL of the item being viewed (by calling makeSearchURI):
* The filter (eg. "filter=bread")
* The other field (eg. "filter_column=level")
* The condition (eg. "filter_compare=greater") -- see SECONDARY_FILTER below
* The thing to compare to (eg. "filter_value=5")
* The page we are on (eg. "page=5")
* The position in that page (eg. "pos=20")
* The sort order (eg. "sort_order=name")
* The maximum number available after doing that particular search (eg. max=1000)
Using that information we can show where this item is in the list. For example, item 20 on page 5 would be 804.
That is: ((page - 1) * QUERY_LIMIT) + (pos - 1). For the user, we show one-relative, that is 805/1000.
With that number, and the search information we can go forwards or backwards by adding or subtracting 1 from "pos".
In the case of crossing a page boundary backwards pos may become negative but that is OK.
The table name we establish from the $handlers table (eg. for action "showOneSpell") we can find out that the table is
the SPELL table. That table also tells us the key for this particular database table.
The we can reconstruct the exact search (filter, sort order and so on) and use the LIMIT clause to narrow down to that
particular record. Then we read that, find its ID (key) and then press on as if the user had selected that key in the
first place.
Finding where you stuffed something up (say around line 1014):
git log --pretty=short -u -L 1010,1020:wow_alpha_utils.php
*/
$VALID_NUMBER = '^[+\-]?\d+$'; // just digits with optional sign
$VALID_FLOAT = '^[+\-]?(\d*\.)?(\d+)$'; // optional sign, optional number and decimal point, then number
$VALID_DATE = '^[\w \-]+$'; // Expect letters, numbers spaces, hyphens
$VALID_DATE_TIME = '^[\w :\-]+$'; // Expect letters, numbers spaces, hyphens, and colons
$VALID_ACTION = '^[\w ]+$'; // actions are usually just words with underscore and maybe numbers and spaces
$VALID_BOOLEAN = '^[01]$'; // must be 0 or 1
$VALID_SQL_ID = '^\w+$'; // SQL names are usually just words with underscore and maybe numbers (max 30 probably)
// filter comparison operators
define ('SECONDARY_FILTER', array (
'equals' => ' = ? ',
'not equals' => ' <> ? ',
'less than' => ' < ? ',
'less than or equals' => ' <= ? ',
'greater than' => ' > ? ',
'greater than or equals' => ' >= ? ',
'masked by any bit' => ' & ? <> 0 ',
'not masked by any bit' => ' & ? = 0 ',
'masked by all bits' => ' & ? = ? ',
'not masked by all bits' => ' & ? <> ? ',
'in set' => ' IN ',
'not in set' => ' NOT IN',
'in range' => ' ', // field >= a AND field <= b
'not in range' => ' NOT ', // NOT (field >= a AND field <= b)
));
function nl2br_http ($text)
{
return str_replace ("\n", "<br>", $text);
} // end of nl2br_http
function fixHTML ($s)
{
return htmlspecialchars ($s, ENT_SUBSTITUTE | ENT_QUOTES | ENT_HTML5);
} // end of fixHTML
function ShowError ($theerror)
{
ShowWarning ($theerror); // pffft!
} // end of ShowError
function ShowWarningH ($theWarning)
{
pageContent (false, '', '', '',
function ($info) use ($theWarning)
{
topSection (false, function ($info) use ($theWarning)
{
topMiddle (false, function ($info) use ($theWarning)
{
boxTitle ('Warning');
echo "<div style='color:yellow'>\n";
echo ("<ul><li>$theWarning</ul>");
echo "</div>\n";
});
});
} , '');
} // end of ShowWarningH
function ShowWarning ($theWarning)
{
ShowWarningH (nl2br_http (fixHTML ($theWarning)));
} // end of ShowWarning
function Problem ($why)
{
ShowError ($why);
echo "</main></body></html>\n";
die ();
} // end of Problem
// Use this before database opened
function MajorProblem ($why)
{
echo "
<div class='modal-container'>
<div class='modal'>
<p class='modal__header'>Error occurred at " . strftime ("%Y-%m-%d %H:%M:%S", time()) . "</p>
<p class='modal__body'>We apologise that there has been a problem with the server ...</p>
<p class='modal__footer'>" . fixHTML ($why) . "</p>
</div>
</main>
</body>
</html>";
die ();
} // end of MajorProblem
function validateArgument ($name, $value, $maxLength, $validation, $decode = false)
{
$value = trim ($value);
// first decode it if required
if ($decode)
$value = urldecode ($value);
if ($maxLength > 0 && strlen ($value) > $maxLength)
{
Problem ("Parameter '$name' is too long");
}
if (strlen ($value) && $validation)
{
if (!preg_match ("\xFF" . $validation . "\xFF" . 'i', $value))
{
Problem ("Parameter '$name' is not in the expected format (unexpected characters).");
}
}
return $value;
} // end of validateArgument
function getGP ($name, $maxLength = 0, $validation = "", $decode = false)
{
if (isset ($_GET [$name]))
return validateArgument ($name, $_GET [$name], $maxLength, $validation, $decode);
if (isset ($_POST [$name]))
return validateArgument ($name, $_POST [$name], $maxLength, $validation, $decode);
return false;
} // getGP
function getP ($name, $maxLength = 0, $validation = "", $decode = false)
{
if (isset ($_POST [$name]))
return validateArgument ($name, $_POST [$name], $maxLength, $validation, $decode);
return false;
} // getP
function getG ($name, $maxLength = 0, $validation = "", $decode = false)
{
if (isset ($_GET [$name]))
return validateArgument ($name, $_GET [$name], $maxLength, $validation, $decode);
return false;
} // getG
function showBacktrace ($howFarBack = 1)
{
echo "<hr><b>Backtrace</b>\n";
echo "<ol>\n";
$bt = debug_backtrace ();
$count = sizeof($bt);
for ($i = $howFarBack; $i < $count; $i++)
{
$item = $bt [$i];
echo "<li>\n";
echo "<ul>\n";
echo ("<li>" . "Function: " . fixHTML ($item ['function']));
echo ("<li>" . "Called from: " . fixHTML ($item ['file']));
echo ("<li>" . "Line: " . fixHTML ($item ['line']));
echo "</ul><p>\n";
}
echo "</ol>\n";
echo "<hr>\n";
} // end of showBacktrace
function columns_compare ($a, $b)
{
return $a ['Field'] <=> $b ['Field'];
} // end of columns_compare
function searchContainerStart ($title, $description)
{
echo "
<!-- PAGE CONTAINER-->
<section class='main-page-container'>
<!-- PAGE TITLE -->
<div class='page-title page-title--search'>
<div class='big-title'>
<i class='page-title__database fas fa-database'></i>
<i class='page-title__angle fas fa-angle-right'></i>
<h1 class='big-title__heading' title='" . fixHTML ($title) . "'>" . fixHTML ($description) . "</h1>
</div>
<!-- SEARCH CONTAINER -->
<div class='search-container'>
";
} // end of searchContainerStart
function searchContainerEnd ()
{
endDiv ('search-container');
endDiv ('page-title page-title--search');
} // end of searchContainerEnd
function columns_sort ($a, $b)
{
return $a ['Field'] <=> $b ['Field'];
} // end of columns_sort
function showSearchForm ($description, $sortFields, $headings, $results, $where, $searchError)
{
global $filter, $action, $sort_order, $params, $page, $matches;
global $filter_column, $filter_compare, $filter_value;
global $searchFields, $extraWhere, $mainTable, $keyName;
if ($sort_order)
$order_clause = "ORDER BY $sort_order";
else
$order_clause = '';
// find maximum matches
$row = dbQueryOneParam ("SELECT COUNT(*) AS count FROM $mainTable $where $order_clause", $params);
$matches = $row ['count'];
$pages = ceil ($matches / QUERY_LIMIT);
if ($page > $pages)
$page = $pages;
$PHP_SELF = $_SERVER['PHP_SELF'];
$sortOptions = array ();
foreach ($sortFields as $field)
{
if ($field == $sort_order)
$selected = "selected = 'selected'";
else
$selected = '';
$sortOptions [] = " <option value='" . fixHTML ($field) . "' $selected>" .
fixHTML (($field)) . "</option>";
} // end of foreach sort field
$mainTableFields = dbQueryParam ("SHOW COLUMNS FROM $mainTable", array ());
$filterOptions = array ();
usort ($mainTableFields, 'columns_sort');
foreach ($mainTableFields as $field)
{
if (preg_match ('`int|float`', $field ['Type']))
{
if ($field ['Field'] == $filter_column)
$selected = "selected = 'selected'";
else
$selected = '';
$filterOptions [] = " <option value='" . fixHTML ($field ['Field']) . "' $selected>" .
fixHTML ($field ['Field']) . "</option>";
} // end of being a number
} // end of foreach field
$comparisonOptions = array ();
foreach (SECONDARY_FILTER as $compare => $operator)
{
if ($compare == $filter_compare)
$selected = "selected = 'selected'";
else
$selected = '';
$comparisonOptions [] = " <option value='" . fixHTML ($compare) . "' $selected>" .
fixHTML ($compare) . "</option>";
} // end of foreach comparison
/*
echo
"<details style='margin-top:3px;'><summary>Regular expression tips</summary>
<ul>
<li><i>A number on its own</i>: the item database ID (key)
<li>Ordinary text: itself
<li>At beginning: ^
<li>At end: $
<li>Word boundaries: [[:<:]]word[[:>:]]
<li>Choice: this|that
<li>Letters: [A-Z]+
<li>Numbers: [0-9]+
<li>Zero or one: x?
<li>One or more: x+
<li>Zero or more: x*
<li>Any character: .
<li>Groups: (this is a group)
</ul>
</details>
</form>";
*/
$resultsCount = count ($results);
$searchURI = makeSearchURI ();
$nextPage = $page + 1;
$prevPage = $page - 1;
searchContainerStart ($mainTable, $description);
echo "
<!-- SEARCH FORM -->
<form method='post' action='$PHP_SELF'>
<input Type=hidden Name=action Value='$action'>
<input Type=hidden Name=page Value='$page'>
<div class='search-bar'>";
// error message here
if ($searchError)
echo "<span>" . fixHTML ($searchError) . "</span>\n";
echo "
<div class='search-bar__main'>
<input
class='custom-input'
type='text'
name='filter'
size='40'
value='" . fixHTML ($filter) . "'
placeholder='ID or regular expression'
autofocus='autofocus'
title='Enter a number, text, or a regular expression.\nRegexp help at: regex101.com'
/>
<label for='sort_order'>Sort by</label>
<select
class='custom-selector'
id='sort_order'
name='sort_order'
size='1'
title='Which column to sort on'
>"
. "\n" . implode("\n", $sortOptions) . "
</select>
</div>
<div class='search-bar__filters'>
<label for='filter_column'>Also match</label>
<select
class='custom-selector'
id='filter_column'
name='filter_column'
size='1'
title='Which database column to filter on'
>"
. "\n" . implode ("\n", $filterOptions) . "
</select>
<select
class='custom-selector'
id='filter_compare'
name='filter_compare'
size='1'
title='What comparison to do'
>"
. "\n" . implode ("\n", $comparisonOptions) . "
</select>
<input
class='custom-input'
type='text'
name='filter_value'
size='15'
value='" . fixHTML ($filter_value) . "'
placeholder='Number/hex/bin'
title='Leave empty for no secondary filtering.
Hex numbers: 0x0123ABCD
Binary numbers: 0b01010
Set: 1,7,9,15
Range: 20 to 30'
/>
</div>
</div>
<button class='search-button'>
<i class='fas fa-search'></i>
</button>
</form> <!-- END SEARCH FORM -->
";
searchContainerEnd ();
echo"
<!-- PAGE CONTENT -->
<div class='creature-details page-content'>
<!-- TABLE CONTAINER -->
<div class='table-container table-container--full'>
<!-- PAGE COUNT -->
<div class='page-counter'>
<div>";
if ($page > 1)
echo "<a href='" . fixHTML ("$PHP_SELF?action=$action$searchURI&page=$prevPage") ."'
><i class='page-counter__left fas fa-angle-double-left'></i
></a>";
if ($pages > 0)
echo "<span>Page $page of $pages</span>";
if ($page < $pages)
echo "<a href='" . fixHTML ("$PHP_SELF?action=$action$searchURI&page=$nextPage") ."'
><i class='page-counter__right fas fa-angle-double-right'></i
></a>";
echo "
</div>
<div>
<span class='page-counter__results-count'>Showing $resultsCount on this page ($matches total matches)</span>
</div>
</div>
<!-- END PAGE COUNT -->
<!-- TABLE -->
<table class='table-rows'>
<thead>";
if (count ($results) > 0)
headings ($headings);
echo "</thead>
<tbody>";
comment ("THE SEARCH RESULTS");
if (count ($results) == 0)
return false;
return true;
} // end of showSearchForm
function wrapUpSearch ()
{
echo "
</tbody>
</table>
<!-- END TABLE -->
</div>
<!-- END TABLE CONTAINER -->
</div>
<!-- END PAGE CONTENT -->
</section>
<!-- END PAGE CONTAINER-->
";
} // end of wrapUpSearch
// work out what our query offset should be
function getQueryOffset ()
{
global $page;
if (!$page || $page < 1)
$page = 1;
return ($page - 1) * QUERY_LIMIT; // first page starts at offset zero
} // end of getQueryOffset
// show how many rows matched a query
function showCount ($results)
{
global $matches, $page;
$s = 's';
if (count ($results) == 1)
$s = '';
echo ("<p>Showing " . count ($results) . " row$s.");
$pages = ceil ($matches / QUERY_LIMIT);
$s1 = 'es';
if ($matches == 1)
$s1 = '';
$s2 = 's';
if ($pages == 1)
$s2 = '';
echo ("<p>$matches match$s1 for this query ($pages page$s2).");
if ($pages > 1)
echo "This is page $page of $pages.";
echo "\n";
} // end of showCount
// This for stuff like EffectTriggerSpell_1, EffectTriggerSpell_2, EffectTriggerSpell_3
// We want to know if any of them are non-zero, because then we display a heading
// eg. $count = getCount ($row, 'EffectTriggerSpell_', 3);
function getCount ($row, $field, $n)
{
$count = 0;
for ($i = 1; $i <= $n; $i++)
if ($row [$field . $i])
$count++;
return $count;
} // end of getCount
function addSign ($value)
{
if ($value > 0)
return '+' . $value;
return $value;
} // end of addSign
function td ($s)
{
echo " <td>";
echo (fixHTML ($s));
echo "</td>\n";
} // end of td
function tdx ($s, $c='tdl')
{
echo " <td>";
echo (fixHTML ($s));
echo "</td>\n";
} // end of tdx
function tdxr ($s)
{
tdx ($s, 'tdr');
} // end of tdxr
// for hyperlinks
function tdhr ($s)
{
echo " <td>$s</td>\n";
} // end of tdhr
function tdh ($s)
{
echo " <td>$s</td>\n";
} // end of tdh
function th ($s)
{
echo " <th>";
echo (fixHTML ($s));
echo "</th>\n";
} // end of th
function headings ($what)
{
global $filter_column, $filter_value;
if (strlen ($filter_value) > 0 && strlen ($filter_column) > 0)
$what [] = $filter_column;
echo " <tr>\n";
foreach ($what as $hdg)
th (' ' . $hdg);
echo " </tr>\n";
} // end of headings
function showFilterColumn ($row)
{
global $filter_column, $filter_value;
if (strlen ($filter_value) > 0 && strlen ($filter_column) > 0)
tdx ($row [$filter_column], 'tdr');
} // end of showFilterColumn
// helper function for initial search, or moving forwards or backwards one item
function setUpSearchHelper ()
{
global $filter, $where, $params, $sort_order;
global $filter_column, $filter_compare, $filter_value, $fixed_filter_value;
global $searchFields, $extraWhere, $mainTable, $keyName;
$where = 'WHERE TRUE ';
$params = array ();
$params [0] = '';
$filter = trim ($filter);
$searchError = '';
if ($filter)
{
// check filter regexp is OK
$ok = @preg_match ("`$filter`", "whatever", $matches);
if ($ok === false)
{
$warnings = error_get_last();
$warning = $warnings ['message'];
$searchError = "Error evaluating regular expression: $filter\n\n$warning.\n\nFILTER IGNORED.";
} // if not OK
else
{
if (preg_match ('|^\d+$|', $filter))
{
$where .= " AND $keyName = ?";
$params = array ('i', &$filter);
}
else
{
$where = '';
$strings = '';
$params = array ('');
foreach ($searchFields as $field)
{
if ($where == '')
$where .= "WHERE ($field REGEXP ? ";
else
$where .= " OR $field REGEXP ? ";
$params [0] .= 's';
$params [] = &$filter;
} // end of for each field to search
$where .= ') ';
} // end of if
} // end of if no error in regexp
} // end of having a filter
// secondary comparison
if (strlen ($filter_value) > 0 && strlen ($filter_column) > 0)
{
// IN SET
if ($filter_compare == 'in set' || $filter_compare == 'not in set')
{
if (!preg_match ('/\s*([+\-]?\d+)(\s*,([+\-]?\d+))*\s*$/', $filter_value))
{
$searchError = 'Filter comparison value "' . $filter_value . '" not a series of comma-separated numbers. SECONDARY FILTER IGNORED.';
}
else
{
$where .= " AND ($filter_column " . SECONDARY_FILTER [$filter_compare]; // ie. IN or NOT IN
$where .= '(' . $filter_value . ')';
$where .= ')';
} // end of if not ignored
} // end of in or not in
// IN RANGE
elseif ($filter_compare == 'in range' || $filter_compare == 'not in range')
{
if (!preg_match ('/\s*([+\-]?\d+)\s+to\s+([+\-]?\d+)\s*$/i', $filter_value, $matches))
{
$searchError = 'Filter comparison value "' . $filter_value . '" not in format: (number) TO (number). ' .
'SECONDARY FILTER IGNORED.';
}
else
{
$where .= " AND (" . SECONDARY_FILTER [$filter_compare]; // ie. NOT or space
$where .= ' (' . $filter_column . ' >= ' . $matches [1] . ' AND ' .
$filter_column . ' <= ' . $matches [2] . ')';
$where .= ')';
} // end of if not ignored
} // end of in range or not in range
// JUST A NUMBER
else
{
if (!preg_match ('/(^[+\-]?\d+$)|(^0[xX][0-9A-Fa-f]+$)|(^0[bB][01]+$)|^[+\-]?(\d*\.)?(\d+)$/', $filter_value))
{
$searchError = 'Filter comparison value "'. $filter_value . '" not decimal, float, hex or binary number. SECONDARY FILTER IGNORED.';
}
else
{
$where .= " AND ($filter_column " . SECONDARY_FILTER [$filter_compare];
$paramType = 'i';
if (strpos ($fixed_filter_value, '.') !== false)
$paramType = 'd'; // turn to a double since it has a decimal place
$params [0] .= $paramType;
$params [] = &$fixed_filter_value;
// [not] masked by all bits needs the value again
if (strstr ($filter_compare, 'all'))
{
$params [0] .= $paramType;
$params [] = &$fixed_filter_value;
}
$where .= ')';
} // end of if not ignored
} // end of NOT (in or not in)
} // end of secondary comparison
if ($sort_order)
$order_clause = "ORDER BY $sort_order";
else
$order_clause = '';
return array ('select' => "SELECT * FROM $mainTable $where $extraWhere $order_clause",
'params' => $params,
'where' => $where,
'error' => $searchError);
} // end of setUpSearchHelper
function setUpSearch ($description, $sortFields, $headings)
{
global $searchFields, $extraWhere, $mainTable, $keyName;
$searchParams = setUpSearchHelper ();
$offset = getQueryOffset(); // based on the requested page number
// do the search
$results = dbQueryParam ($searchParams ['select'] . " LIMIT $offset, " . QUERY_LIMIT,
$searchParams ['params']);
// now show the search form
if (!showSearchForm ($description, $sortFields, $headings, $results, $searchParams ['where'] . ' ' . $extraWhere, $searchParams ['error']))
{
comment ("SETTING UP SEARCH FORM FAILED");
return false;
}
// let them display the results
return $results;
} // end of setUpSearch
// shows all fields from any table
// $limit is a table of the only keys we are interested in
function showOneThing ($table, $key, $id, $description, $nameField, $expand, $limit = false)
{
$info = dbQueryParam ("SHOW COLUMNS FROM $table", array ());
$row = dbQueryOneParam ("SELECT * FROM $table WHERE $key = ?", array ('i', &$id));
if (!$row)
{
ShowWarning ("$description $id is not on the database");
return;
}
if ($description)
boxTitle ($description);
if (!$limit && preg_match ('|\.(.+)$|', $table, $matches))
{
$tableOnly = $matches [1];
// add a box for displaying SQL update information for copy/paste into an update line
echo "<div id='editing_sql' class='sql-statement'>UPDATE `$tableOnly` SET `<span id='sql_field_name'>field</span>`
= xxxx WHERE (`$key` = " .
$row [$key] . ");\n
</div>\n";
}
if ($limit)
echo "<table class='table-fields'>\n";
else
echo "<table class='table-rows'>\n";
echo "<thead>\n";
echo "<tr>\n";
th ('Field');
th ('Value');
echo "</tr>\n";
echo "</thead>\n";
echo "<tbody>\n";
foreach ($info as $col)
{
$fieldName = $col ['Field'];
if ($limit && !in_array ($fieldName, $limit))
continue;
// the row will generate an SQL update if you Alt+click it
if ($limit)
echo " <tr>\n";
else
echo " <tr onclick='onRowClick(event,this.id)' id='field_$fieldName'>\n";
tdx ($fieldName);
// check if we can be more informative, like show an item name
if (isset ($expand [$fieldName]))
expandField ($row [$fieldName], $expand [$fieldName]);
else
tdx ($row [$fieldName], preg_match ('/text/', $col ['Type']) ? 'tdl' : 'tdr');
echo " </tr>\n";
} // end of foreach
echo "</tbody>\n";
echo "</table>\n";
/*
// extra stuff
if ($func)
{
echo "<div class='one_thing_section'>\n";
$func ($id, $row);
echo "</div>\n"; // end of other stuff
}
echo "</div>\n"; // end of flex container
*/
} // end of showOneThing
// for hyperlinks to things with a name we can show (like a quest name)
function lookupThing ($array, $id, $action)
{
$link = "<a href='?action=$action&id=$id'>$id</a>";
if (!$id)
return ('-');
elseif (array_key_exists ($id, $array))
return ("$link: <a href='?action=$action&id=$id'>" . fixHTML ($array [$id]) . '</a>' );
return ("$id (not found)");
} // end of lookupThing
// for hyperlinks to things with no name to be shown
function makeLink ($id, $action)
{
if (!$id)
return ('-');
return "<a href='?action=$action&id=$id'>$id</a>";
} // end of makeLink
function convertTimeMinutes ($time, $ms = true)
{
// some things seem to have negative time
if ($time <= 0)
return $time;
if ($ms)
$time /= 1000;
return round ($time / 60, 1);
} // end of convertTimeMinutes
function convertTimeSeconds ($time)
{
// some things seem to have negative time
if ($time <= 0)
return $time;
$time /= 1000;
return $time;
} // end of convertTimeSeconds
function convertTimeGeneral ($time)
{
// some things seem to have negative time
if ($time <= 0)
return $time;
$time /= 1000;
// small times show in seconds
if ($time < 60)
return $time . ' sec';
// up to an hour show in minutes
if ($time < 3600)
return round ($time / 60, 1) . ' min';
// otherwise show in hours
return round ($time / 3600, 1) . ' hour';
} // end of convertTimeGeneral
function listThing ($array, $id, $action, $info = '', $info2 = '', $title = '')
{
if (array_key_exists ($action, ICONS))
$icon = ICONS [$action];
else
$icon = 'fa-table';
$title = fixHTML ($title);
// if they are known, make a hyperlink
if (array_key_exists ($id, $array ))
{
$link = "<a href='?action=$action&id=$id' class='row-card' title='$title'>";
$unlink = '</a>';
$description = fixHTML ($array [$id]);
}
else
{
$link = "<div class='row-card' title='$title'>";
$unlink = '</div>';
$description = "(not found)";
}
echo "
$link
<span class='row-card__head'>
<i class='fas $icon'></i>$id</span>
<span class='row-card__content'>$description</span>
";
if ($info)
echo "<span class='row-card__extra'>" . fixHTML ($info) . "</span>\n";
if ($info2)
echo "<span class='row-card__extra'>" . fixHTML ($info2) . "</span>\n";
echo "
$unlink
";
} // end of listThing
function convertGold ($amount)
{
if ($amount == 0)
return '0';
$copper = $amount;
$gold = intval ($copper / 10000);
$copper -= $gold * 10000;
$silver = intval ($copper / 100);
$copper -= $silver * 100;
$result = '';
if ($gold)
$result .= $gold . 'g ';
if ($silver)
$result .= $silver . 's ';
if ($copper)
$result .= $copper . 'c';
return $result;
} // end of convertGold
function showSpawnPoints ($results, $heading, $tableName, $idName, $xName, $yName, $zName, $mName, $mTypeName = false, $showMap = false)
{
global $maps;
if (count ($results) == 0 && $showMap === false)
return;
$map0 = 0;
$map1 = 0;
foreach ($results as $spawnRow)
if ($spawnRow [$mName] == 0)
$map0 ++; // Eastern Kingdoms
elseif ($spawnRow [$mName] == 1)
$map1 ++; // Kalimdor
if ($showMap !== false)
if ($showMap === 0)
$map0 = 1;
else
$map1 = 1;
// the display size
$imageWidth = 345;
$imageHeight = 650;
$mapName = '';
if ($map0 > 0)
{
$mapName = 'Eastern_Kingdoms';
// see: map_calculations.lua to get these figures
$mapLeftPoint = 4267.7658363136;
$mapTopPoint = 4657.9751308793;
$mapWidth = 10568.022008253;
$mapHeight = 19980.94603272;
$mapNumber = 0;
}
elseif ($map1 > 0)
{
$mapName = 'Kalimdor';
// see: map_calculations.lua to get these figures
$mapLeftPoint = 5042.4865925889;
$mapTopPoint = 11763.324337648;
$mapWidth = 13100.059130778;
$mapHeight = 24611.604572322;
$mapNumber = 1;
}
if (!$mapName)
return;
comment ("Drawing $mapName");
// get width and height
/*
$imageSize = getimagesize ("maps/$mapName.jpg");
$imageWidth = $imageSize [0];
$imageHeight = $imageSize [1];
*/
echo "<div class='map-container'
id='map-container-$mapName'
onmousedown='onMouseDownMapContainer(event)'
onmouseup='onMouseUpMapContainer(event)'
onmousemove='onMouseMoveMapContainer(event)'
onwheel='onMouseWheelMapContainer(event)'
draggable='false'
style='position:relative; background-color:#172e46;'
>\n";