-
Notifications
You must be signed in to change notification settings - Fork 0
/
adr_shops.php
2222 lines (1925 loc) · 80.2 KB
/
adr_shops.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
/***************************************************************************
* adr_shops.php
* ------------------------
* begin : 08/02/2004
* copyright : Malicious Rabbit / Dr DLP
*
*
***************************************************************************/
/***************************************************************************
*
* 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 2 of the License, or
* (at your option) any later version.
*
*
***************************************************************************/
define('IN_PHPBB', true);
define('IN_ADR_SHOPS', true);
define('IN_ADR_CHARACTER', true);
define('IN_ADR_CELL', true);
define('IN_ADR_BATTLE', true);
define('IN_ADR_TEMPLE', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
$loc = 'shops';
$sub_loc = 'adr_shops';
//
// Start session management
$userdata = session_pagestart($user_ip, PAGE_ADR);
init_userprefs($userdata);
// End session management
//
include($phpbb_root_path . 'adr/includes/adr_global.'.$phpEx);
$user_id = $userdata['user_id'];
$points = $userdata['user_points'];
$character_id = $userdata['username'];
// Sorry , only logged users ...
if ( !$userdata['session_logged_in'] )
{
$redirect = "adr_shops.$phpEx";
$redirect .= ( isset($user_id) ) ? '&user_id=' . $user_id : '';
header('Location: ' . append_sid("login.$phpEx?redirect=$redirect", true));
}
// Includes the tpl and the header
adr_template_file('adr_shops_body.tpl');
include($phpbb_root_path . 'includes/page_header.'.$phpEx);
// Get the general config
$adr_general = adr_get_general_config();
adr_enable_check();
adr_ban_check($user_id);
adr_character_created_check($user_id);
// Deny access if the user is into a battle or is imprisoned
adr_battle_cell_check($user_id, $userdata);
$points_name = get_reward_name() ? get_reward_name() : $lang['Adr_default_points_name'];
$quantity = ($_POST['quantity']) ? intval($_POST['quantity']) : 1 ;
$start = ( isset($_GET['start']) ) ? intval($_GET['start']) : 0;
$item_id = intval($_GET['item_id']);
$shop_owner_id = intval($_GET['shop_owner_id']);
$shop_id = intval($_GET['shop_id']);
### START restriction checks ###
$adr_user = adr_get_user_infos($user_id);
$item_sql = adr_make_restrict_sql($adr_user);
### END restriction checks ###
if ( !$shop_id )
{
$sql = "SELECT * FROM " . ADR_SHOPS_TABLE . "
WHERE shop_owner_id = $shop_owner_id ";
$result = $db->sql_query($sql);
if( !$result )
{
message_die(GENERAL_ERROR, 'Could not obtain shops information', "", __LINE__, __FILE__, $sql);
}
$row = $db->sql_fetchrow($result);
$shop_id = intval($row['shop_id']);
}
if ( isset($_POST['mode']) && !empty($_POST['mode']) )
{
$mode = htmlspecialchars($_POST['mode']);
}
else if ( isset($_GET['mode']) )
{
$mode = htmlspecialchars($_GET['mode']);
}
else
{
$mode = "view_store_list";
}
if ( $mode != "" )
{
switch($mode)
{
case 'buy':
// Define some values
$shop_id = intval($_GET['shop_id']);
if(!$shop_id) $shop_id = 1;
$store_id = intval($_POST['store_id']);
if(!$store_id) $store_id = 0;
$shop_owner_id = intval($_POST['shop_owner_id']);
if(!$shop_owner_id) $shop_owner_id = 1;
$items = (isset($_POST['item_box'])) ? $_POST['item_box'] : array();
$buying_checks = FALSE;
// Check is buying from forum or user store
$sql_buy_check = ($shop_owner_id != '1') ? 'AND item_in_shop = 1' : '';
// Grab all inventory array..fetchrowset will save on ALOT of sql queries here!
$sql = "SELECT * FROM ". ADR_SHOPS_ITEMS_TABLE ."
WHERE item_owner_id = '$shop_owner_id'
AND item_in_shop = '1'
$sql_buy_check
AND item_in_warehouse = '0'
AND item_monster_thief = '0'";
$result = $db->sql_query($sql);
if (!$result)
message_die(GENERAL_ERROR, 'Could not obtain inventory infos', '', __LINE__, __FILE__, $sql);
$invent_array = $db->sql_fetchrowset($result);
if(count($items) > '0'){
// First check if enough quota for trade
if(($adr_general['Adr_character_limit_enable'] != '0') && ($adr_user['character_trading_limit'] < '1'))
adr_previous(Adr_trading_limit, adr_shops, '');
for($i = 0; $i < count($items); $i++){
$item_id = $items[$i];
$nav = "view_store&shop_id=".$shop_id."";
$item_price = 0;
$new_item_id = $items[$i];
for($j = 0; $j < $quantity; $j++){
for($in = 0; $in < count($invent_array); $in++){
if($new_item_id == $invent_array[$in]['item_id']){
$item_price = (adr_use_skill_trading($user_id, $invent_array[$in]['item_price'], buy) + $item_price);
}
}
}
// Check for user_points
if(get_reward($user_id) < $item_price){
adr_previous(Adr_lack_points, adr_shops, $nav);}
else{
for($j = 0; $j < $quantity; $j++){
$price = adr_buy_item($user_id, $item_id, $shop_owner_id, $shop_id, adr_shops, "see_shop&shop_id=".$shop_id."");
$sum = intval($sum + $price);
$buying_checks = TRUE;
}
}
}
}
// Remove quota
if(($buying_checks == TRUE) && ($adr_general['Adr_character_limit_enable'] == '1')){
adr_trading_limit($user_id);}
if($shop_owner_id > '1'){
// Update user store transaction log
if(count($items) > '0') adr_update_store_user_trans($user_id, $shop_owner_id, $items, $sum, $invent_array);
$direction = append_sid("adr_shops.$phpEx?mode=see_shop&shop_id=".$shop_id);
}
elseif($shop_owner_id == '1'){
// Update store status
adr_update_store_status($user_id, $store_id, $items, $quantity);
$direction = append_sid("adr_shops.$phpEx?mode=view_store&shop_id=".$shop_id);
}
// Create confirmation msg
$message = sprintf($lang['Adr_buy_item_success'], $sum, $points_name);
$message .= '<br /><br />'.sprintf($lang['Adr_return'], "<a href=\"" . $direction . "\">", "</a>");
message_die(GENERAL_MESSAGE, $message);
break;
case 'buy_admin' :
// Define some values
$shop_id = intval($_GET['shop_id']);
if ( !$shop_id ) $shop_id = 1;
$shop_owner_id = intval($_POST['shop_owner_id']);
if ( !$shop_owner_id ) $shop_owner_id = 1;
$items = ( isset($_POST['item_box']) ) ? $_POST['item_box'] : array();
if ( count($items) > 0 )
{
for($i = 0; $i < count($items); $i++)
{
$item_id = $items[$i];
for ( $j = 0 ; $j < $quantity ; $j ++ )
{
$sum = intval($sum + adr_buy_admin_item($user_id , $item_id , $shop_owner_id , $shop_id , adr_shops , "?mode=see_shop&shop_id=".$shop_id."") );
}
}
}
$direction = append_sid("adr_shops.$phpEx?mode=view_store_admin");
$message = $lang['Adr_admin_move_success'];
$message .= '<br /><br />'.sprintf($lang['Adr_return'],"<a href=\"" . $direction . "\">", "</a>") ;
message_die ( GENERAL_MESSAGE , $message );
break;
case 'steal':
// Define some values
$shop_id = intval($_GET['shop_id']);
if(!$shop_id) $shop_id = 1;
$shop_owner_id = intval($_POST['shop_owner_id']);
$store_id = intval($_POST['store_id']);
if(!$store_id) $store_id = 0;
$items = (isset($_POST['item_box'])) ? $_POST['item_box'] : array();
// Loop is broken after item 1 to prevent numerous steals...easier to manage.
if(count($items) > '0'){
for($i = 0; $i < count($items); $i++){
$item_id = $items[$i];
adr_steal_item($user_id, $item_id, $shop_owner_id, $shop_id);
break;
}
}
break;
case 'give' :
adr_template_file('adr_inventory_give_body.tpl');
$s_hidden_fields = '<input type="hidden" name="mode" value="give_item" />';
$s_hidden_fields .= '<input type="hidden" name="cat" value="'.$cat.'" />';
// Define some values
$items = ( isset($_POST['item_box']) ) ? $_POST['item_box'] : array();
$item_id_list .= '(';
if ( count($items) > 0 )
{
for($i = 0; $i < count($items); $i++)
{
$item_id_list .= $items[$i].',';
}
}
$item_id_list .= '0)';
$sql = "SELECT i.* FROM " . ADR_SHOPS_ITEMS_TABLE . " i
WHERE i.item_owner_id = $user_id
AND i.item_in_shop = 0
AND i.item_duration > 0
AND i.item_auth = 1
AND i.item_id IN $item_id_list
ORDER BY i.item_name ";
if( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Could not obtain items information', "", __LINE__, __FILE__, $sql);
}
$items = $db->sql_fetchrowset($result);
$items_name = '';
while( list(,$item) = @each($items) )
{
$item_id = $item['item_id'];
$s_hidden_fields .= '<input type="hidden" name="'.$item_id.'" value="1" />';
$items_name .= adr_get_lang($item['item_name']);
$items_name .= '<br />';
}
$sql = "SELECT * FROM " . USERS_TABLE . "
WHERE user_id > 1
AND user_id <> $user_id
ORDER BY username ";
$result = $db->sql_query($sql);
if( !$result )
{
message_die(GENERAL_ERROR, 'Could not obtain items information', "", __LINE__, __FILE__, $sql);
}
$users = $db->sql_fetchrowset($result);
$give_to = '<select name="give_to">';
for ($t = 0 ; $t < count($users) ; $t++ )
{
$give_to .= '<option value = "'.$users[$t]['user_id'].'">' . $users[$t]['username'] . '</option>';
}
$give_to .= '</select>';
$sql = "SELECT * FROM " . ADR_SHOPS_ITEMS_TABLE ."
WHERE item_id = $item_id
AND item_owner_id = $user_id ";
$result = $db->sql_query($sql);
if( !$result )
{
adr_previous( Adr_shop_items_failure_deleted , adr_shops , '');
}
$items = $db->sql_fetchrow($result);
$template->assign_vars(array(
"GIVE_TO" => $give_to,
"L_ITEM_DONATION" => sprintf($lang['Adr_items_donation'],'<br />'.$items_name),
"L_GIVE_TO" => $lang['Adr_items_give_to'],
"L_SUBMIT" => $lang['Submit'],
"S_ITEMS_ACTION" => append_sid("adr_shops.$phpEx"),
"S_HIDDEN_FIELDS" => $s_hidden_fields,
));
break;
case 'give_item' :
$to_user_id = ( !empty($_POST['give_to']) ) ? $_POST['give_to'] : $_GET['give_to'];
$sql = "SELECT * FROM " . ADR_SHOPS_ITEMS_TABLE . "
WHERE item_owner_id = 1
AND item_in_shop = 0
AND item_duration > 0
AND item_auth = 1 ";
if( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, $lang['Adr_shop_items_failure_deleted']);
}
$items = $db->sql_fetchrowset($result);
while( list(,$item) = @each($items) )
{
if ( isset($_POST[$item['item_id']]))
{
$item_id = $item['item_id'];
adr_give_item($user_id , $to_user_id , $item_id );
}
}
adr_previous( Adr_give_item_success , adr_shops , '' );
break;
case 'sell' :
// Define some values
$items = ( isset($_POST['item_box']) ) ? $_POST['item_box'] : array();
$item_id_list .= '(';
if ( count($items) > 0 )
{
for($i = 0; $i < count($items); $i++)
{
$item_id_list .= $items[$i].',';
}
}
$item_id_list .= '0)';
$sql = "SELECT i.* FROM " . ADR_SHOPS_ITEMS_TABLE . " i
WHERE i.item_owner_id = $user_id
AND i.item_in_shop = 0
AND i.item_duration > 0
AND i.item_auth = 0
AND i.item_id IN $item_id_list
ORDER BY i.item_name ";
if( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Could not obtain items information', "", __LINE__, __FILE__, $sql);
}
$items = $db->sql_fetchrowset($result);
$items_name = '';
while( list(,$item) = @each($items) )
{
$item_id = $item['item_id'];
$temp_price = adr_get_item_real_price($item_id , $user_id);
$price = intval($price + adr_use_skill_trading($user_id , $temp_price , sell));
$s_hidden_fields .= '<input type="hidden" name="'.$item_id.'" value="1" />';
}
adr_template_file('adr_confirm_body.tpl');
$template->assign_block_vars('sell_item' , array());
$s_hidden_fields .= '<input type="hidden" name="cat" value="'.$cat.'" />';
$s_hidden_fields .= '<input type="hidden" name="mode" value="sell_item" />';
$template->assign_vars(array(
'MESSAGE_TITLE' => $lang['Adr_items_sell_confirm'],
'MESSAGE_TEXT' => sprintf($lang['Adr_items_sell_confirm_price'], intval($price) , get_reward_name() ),
'L_YES' => $lang['Yes'],
'L_NO' => $lang['No'],
'S_SELL_CONFIRM_ACTION' => append_sid("adr_shops.$phpEx"),
'HIDDEN_FIELDS' => $s_hidden_fields,
));
break;
case 'create_shop' :
$sql = "SELECT shop_id FROM " . ADR_SHOPS_TABLE . "
WHERE shop_owner_id = $user_id ";
$result = $db->sql_query($sql);
if( !$result )
{
message_die(GENERAL_ERROR, 'Could not obtain shops information', "", __LINE__, __FILE__, $sql);
}
$row = $db->sql_fetchrow($result);
if ( is_numeric($row['shop_id']) )
{
adr_previous ( Adr_users_shops_already , adr_shops , '' );
}
else
{
$template->assign_block_vars('create_shop',array());
}
$adr_general = adr_get_general_config();
$template->assign_vars(array(
'L_CREATE_NEW_SHOP' => $lang['Adr_users_shops_create'],
'L_CREATE_NEW_SHOP_PRICE' => sprintf( $lang['Adr_users_shops_create_price'], $adr_general['new_shop_price'] , get_reward_name() ),
'L_CREATE_NEW_SHOP_NAME' => $lang['Adr_users_shops_create_name'],
'L_CREATE_NEW_SHOP_DESC' => $lang['Adr_users_shops_create_desc'],
'L_SUBMIT' => $lang['Submit'],
));
break;
case 'delete_item' :
// Define some values
$shop_id = intval($_GET['shop_id']);
if ( !$shop_id ) $shop_id = 1;
$shop_owner_id = intval($_POST['shop_owner_id']);
$items = ( isset($_POST['item_box']) ) ? $_POST['item_box'] : array();
if ( count($items) > 0 )
{
for($i = 0; $i < count($items); $i++)
{
$item_id = $items[$i];
$sql = "DELETE FROM " . ADR_SHOPS_ITEMS_TABLE ."
WHERE item_owner_id = $user_id
AND item_id = $item_id
AND item_in_shop = 1 ";
if( !$db->sql_query($sql) )
{
message_die(GENERAL_ERROR, 'Could not obtain items information', "", __LINE__, __FILE__, $sql);
}
}
}
adr_previous( Adr_shop_items_successful_deleted , adr_shops , "mode=see_shop&shop_id=".$shop_id."" );
break;
case 'inventory' :
$sql = "SELECT shop_id FROM " . ADR_SHOPS_TABLE . "
WHERE shop_owner_id = $user_id ";
$result = $db->sql_query($sql);
if( !$result )
{
message_die(GENERAL_ERROR, 'Could not obtain shops information', "", __LINE__, __FILE__, $sql);
}
$row = $db->sql_fetchrow($result);
if ( !(is_numeric($row['shop_id'])) )
{
adr_previous( Adr_lack_shops , adr_character_inventory , '' );
}
// Define some values
$shop_id = intval($_GET['shop_id']);
if ( !$shop_id ) $shop_id = 1;
$shop_owner_id = intval($_POST['shop_owner_id']);
$items = ( isset($_POST['item_box']) ) ? $_POST['item_box'] : array();
if ( count($items) > 0 )
{
for($i = 0; $i < count($items); $i++)
{
$item_id = $items[$i];
$sql = "UPDATE " . ADR_SHOPS_ITEMS_TABLE ."
SET item_in_shop = 0,
item_in_warehouse = 0
WHERE item_id = $item_id
AND item_owner_id = $user_id ";
if( !$db->sql_query($sql) )
{
message_die(GENERAL_ERROR, 'Could not obtain items information', "", __LINE__, __FILE__, $sql);
}
}
}
adr_previous( Adr_shop_items_successful_removed , adr_shops , "mode=see_shop&shop_id=".$shop_id."" );
break;
case 'shop_edit' :
$sql = "SELECT * FROM " . ADR_SHOPS_TABLE . "
WHERE shop_owner_id = $user_id ";
$result = $db->sql_query($sql);
if( !$result )
{
message_die(GENERAL_ERROR, 'Could not obtain shops information', "", __LINE__, __FILE__, $sql);
}
$row = $db->sql_fetchrow($result);
if ( !(is_numeric($row['shop_id'])) )
{
adr_previous ( Adr_lack_shops , adr_shops , '' );
}
else
{
$template->assign_block_vars('edit_shop',array());
}
$template->assign_vars(array(
'SHOP_ID' => $row['shop_id'],
'SHOP_NAME' => $row['shop_name'],
'SHOP_DESC' => $row['shop_desc'],
'L_CREATE_NEW_SHOP' => $lang['Adr_users_shops_edit'],
'L_CREATE_NEW_SHOP_NAME' => $lang['Adr_users_shops_create_name'],
'L_CREATE_NEW_SHOP_DESC' => $lang['Adr_users_shops_create_desc'],
'L_SUBMIT' => $lang['Submit'],
));
break;
case 'shop_delete' :
$sql = "SELECT * FROM " . ADR_SHOPS_TABLE . "
WHERE shop_owner_id = $user_id ";
$result = $db->sql_query($sql);
if( !$result )
{
message_die(GENERAL_ERROR, 'Could not obtain shops information', "", __LINE__, __FILE__, $sql);
}
$row = $db->sql_fetchrow($result);
if ( !(is_numeric($row['shop_id'])) )
{
adr_previous ( Adr_lack_shops , adr_shops , '' );
}
$sql = "UPDATE " . ADR_SHOPS_ITEMS_TABLE ."
SET item_in_shop = 0
WHERE item_owner_id = $user_id ";
if( !$db->sql_query($sql) )
{
message_die(GENERAL_ERROR, 'Could not obtain items information', "", __LINE__, __FILE__, $sql);
}
$sql = "DELETE FROM " . ADR_SHOPS_TABLE ."
WHERE shop_owner_id = $user_id ";
if( !$db->sql_query($sql) )
{
message_die(GENERAL_ERROR, 'Could not obtain items information', "", __LINE__, __FILE__, $sql);
}
// Remove all transaction logs for user store
$sql = "DELETE FROM " . ADR_STORES_USER_HISTORY ."
WHERE user_store_owner_id = '$user_id'";
if( !$db->sql_query($sql) ){
message_die(GENERAL_ERROR, 'Could not delete user store trans logs', "", __LINE__, __FILE__, $sql);}
adr_previous( Adr_users_shops_deleted , adr_shops , '' );
break;
case 'save_new_shop' :
$adr_general = adr_get_general_config();
adr_substract_points( $user_id , $adr_general['new_shop_price'] , adr_shops , '?mode=create_shop' );
$sql = "SELECT * FROM " . ADR_SHOPS_TABLE ."
ORDER BY shop_id
DESC LIMIT 1";
$result = $db->sql_query($sql);
if( !$result )
{
message_die(GENERAL_ERROR, 'Could not obtain alignments information', "", __LINE__, __FILE__, $sql);
}
$fields_data = $db->sql_fetchrow($result);
$shop_name = ( isset($_POST['shop_name']) ) ? trim($_POST['shop_name']) : trim($_GET['shop_name']);
$shop_desc = ( isset($_POST['shop_desc']) ) ? trim($_POST['shop_desc']) : trim($_GET['shop_desc']);
$shop_id = $fields_data['shop_id'] +1;
if ( !$shop_name )
{
message_die(MESSAGE, $lang['Fields_empty']);
}
$sql = "INSERT INTO " . ADR_SHOPS_TABLE . "
( shop_id , shop_name , shop_desc , shop_owner_id )
VALUES ( $shop_id ,'" . str_replace("\'", "''", $shop_name) . "','" . str_replace("\'", "''", $shop_desc) . "', $user_id )";
$result = $db->sql_query($sql);
if( !$result )
{
message_die(GENERAL_ERROR, "Couldn't insert new shop", "", __LINE__, __FILE__, $sql);
}
adr_previous ( Adr_users_shops_create_success , adr_shops , '' );
break;
case 'save_shop' :
$shop_name = ( isset($_POST['shop_name']) ) ? trim($_POST['shop_name']) : trim($_GET['shop_name']);
$shop_desc = ( isset($_POST['shop_desc']) ) ? trim($_POST['shop_desc']) : trim($_GET['shop_desc']);
$shop_id = ( !empty($_POST['shop_id']) ) ? $_POST['shop_id'] : $_GET['shop_id'];
if ( !$shop_name )
{
message_die(MESSAGE, $lang['Fields_empty']);
}
$sql = "UPDATE " . ADR_SHOPS_TABLE . "
SET shop_name = '". str_replace("\'", "''", $shop_name) . "',
shop_desc = '" . str_replace("\'", "''", $shop_desc) . "'
WHERE shop_id = $shop_id
AND shop_owner_id = $user_id ";
$result = $db->sql_query($sql);
if( !$result )
{
message_die(GENERAL_ERROR, "Couldn't insert new shop", "", __LINE__, __FILE__, $sql);
}
adr_previous ( Adr_users_shops_edited_success , adr_shops , "?mode=see_shop&shop_id=".$shop_id."" );
break;
case 'search_item' :
$template->assign_block_vars('search_item',array());
$template->assign_vars(array(
'ITEM_TYPE' => adr_get_item_type(0,search),
'ITEM_QUALITY' => adr_get_item_quality(0,search),
'L_POINTS' => get_reward_name(),
'L_ITEM_QUALITY' => $lang['Adr_items_quality'],
'L_ITEM_TYPE' => $lang['Adr_items_type_use'],
'L_ITEM_QUALITY_LEAST' => $lang['Adr_items_type_least'],
'L_ITEM_POWER_LEAST' => $lang['Adr_items_power_least'],
'L_ITEM_DURATION_LEAST' => $lang['Adr_items_duration_least'],
'L_ITEM_PRICE_MAX' => $lang['Adr_items_price_max'],
'L_SEARCH_ITEM_CRITERA' => $lang['Adr_items_search_criteria'],
'L_SUBMIT' => $lang['Submit'],
));
break;
case 'search_item_results':
$template->assign_block_vars('search_item_results', array());
$item_quality = (intval($_POST['item_quality']) -1);
$item_power_least = (intval($_POST['item_power_least']) -1);
$item_duration_least = (intval($_POST['item_duration_least']) -1);
$item_type = intval($_POST['item_type_use']);
$item_price_max = intval($_POST['item_price_max']);
// Check user input for errors
$item_quality = ($item_quality < '0') ? intval(0) : $item_quality;
$item_power_least = ($item_power_least < '0') ? intval(0) : $item_power_least;
$item_duration_least = ($item_duration_least < '0') ? intval(0) : $item_duration_least;
$search_type_sql = ($item_type > '0') ? 'AND item_type_use = '.$item_type : '';
$search_price_sql = ($item_price_max > '0') ? 'AND item_price < '.$item_price_max : '';
// $sql = "SELECT i.*, s.*, q.item_quality_lang, t.item_type_lang FROM " . ADR_SHOPS_ITEMS_TABLE . " i, " . ADR_SHOPS_TABLE . " s
$sql = "SELECT i.*, s.*, q.item_quality_lang, t.item_type_lang FROM (" . ADR_SHOPS_ITEMS_TABLE . " i, " . ADR_SHOPS_TABLE . " s)
LEFT JOIN " . ADR_SHOPS_ITEMS_QUALITY_TABLE . " q ON (i.item_quality = q.item_quality_id)
LEFT JOIN " . ADR_SHOPS_ITEMS_TYPE_TABLE . " t ON (i.item_type_use = t.item_type_id)
WHERE i.item_quality > '$item_quality'
AND i.item_power > '$item_power_least'
AND i.item_duration > '$item_duration_least'
AND i.item_owner_id = s.shop_owner_id
AND i.item_auth = '0'
AND ((i.item_in_shop = '1' AND s.shop_id != '1') OR (i.item_in_shop = '0' AND s.shop_id = '1'))
$search_type_sql
$search_price_sql
ORDER BY i.item_price";
if(!($result = $db->sql_query($sql))){
message_die(GENERAL_ERROR, 'Could not query items', '', __LINE__, __FILE__, $sql);}
$row = $db->sql_fetchrowset($result);
// If no results then no items to display for search criteria
if(!(count($row))){
adr_previous(Adr_search_no_results, adr_shops, 'mode=search_item');}
for($f = 0; $f < count($row); $f++)
{
$row_class = (!($f % 2)) ? $theme['td_class1'] : $theme['td_class2'];
$template->assign_block_vars('search_item_results.items', array(
"ROW_CLASS" => $row_class,
"ITEM_NAME" => adr_get_lang($row[$f]['item_name']),
"ITEM_QUALITY" => $lang[$row[$f]['item_quality_lang']],
"ITEM_DURATION" => $row[$f]['item_duration'],
"ITEM_DURATION_MAX" => $row[$f]['item_duration_max'],
"ITEM_POWER" => $row[$f]['item_power'],
"ITEM_PRICE" => $row[$f]['item_price'],
"ITEM_WEIGHT" => $row[$f]['item_weight'],
"ITEM_TYPE" => $lang[$row[$f]['item_type_lang']],
"SHOP_NAME" => adr_get_lang($row[$f]['shop_name']),
"U_ITEM_INFO" => append_sid("adr_shops.$phpEx?mode=view_item&item_id=".$row[$f]['item_id'].""),
"U_SHOP_NAME" => append_sid("adr_shops.$phpEx?mode=see_shop&shop_id=".$row[$f]['shop_id'])
));
}
$template->assign_vars(array(
'L_SHOP_NAME' => $lang['Adr_shop_name'],
'L_ITEM_QUALITY' => $lang['Adr_items_quality'],
'L_ITEM_TYPE' => $lang['Adr_items_type_use'],
"L_ITEM_NAME" => $lang['Adr_shops_categories_item_name'],
"L_ITEM_POWER" => $lang['Adr_items_power'],
"L_ITEM_WEIGHT" => $lang['Adr_character_weight'],
"L_ITEM_DURATION" => $lang['Adr_items_duration'],
"L_ITEM_PRICE" => $lang['Adr_items_price'],
'L_SUBMIT' => $lang['Submit'],
));
break;
case 'view_store_list' :
$template->assign_block_vars('view_store_list',array());
// All user view stores
$sql = "SELECT * FROM " . ADR_STORES_TABLE . "
WHERE store_admin = 0
ORDER BY store_name ASC ";
$result = $db->sql_query($sql);
if( !$result )
{
message_die(GENERAL_ERROR, 'Could not obtain custom store info', "", __LINE__, __FILE__, $sql);
}
if ( $row = $db->sql_fetchrow($result) )
{
$i = 0;
do
{
$row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
if ( $row['store_status'] == 1 )
{
$store_status = $lang['Adr_store_open'];
}
else
{
$store_status = $lang['Adr_store_closed'];
}
if ( $row['store_img'] != '' )
{
$store_img = '<img src="adr/images/store/' . $row['store_img'] . '">';
}
else
{
$store_img = '';
}
$template->assign_block_vars('view_store_list.store', array(
"ROW_CLASS" => $row_class,
"STORE_NAME" => $row['store_name'],
"STORE_DESC" => $row['store_desc'],
"STORE_IMG" => $store_img,
"STORE_STATUS" => $store_status,
"U_STORE_NAME" => append_sid("adr_shops.$phpEx?mode=view_store&shop_id=".$row[ 'store_id']),
));
$i++;
}
while ( $row = $db->sql_fetchrow($result) );
}
if ( $userdata['user_level'] == ADMIN )
{
// Admin only stores
$sql = "SELECT * FROM " . ADR_STORES_TABLE . "
WHERE store_admin = 1
ORDER BY store_name ASC ";
$result = $db->sql_query($sql);
if( !$result )
{
message_die(GENERAL_ERROR, 'Could not obtain custom store info', "", __LINE__, __FILE__, $sql);
}
if ( $admin = $db->sql_fetchrow($result) )
{
$i = 0;
do
{
$row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
if ( $admin['store_img'] != '' )
{
$store_img = '<img src="adr/images/store/' . $admin['store_img'] . '">';
}
if ( $admin['store_img'] == '' )
{
$store_img = '';
}
if ( $admin['store_admin'] == 1 )
{
$store_auth = $lang['Adr_store_admin'];
}
$template->assign_block_vars('view_store_list.admin', array(
"ROW_CLASS" => $row_class,
"STORE_NAME" => $admin['store_name'],
"STORE_DESC" => $admin['store_desc'],
"STORE_IMG" => $admin['store_img'],
"STORE_STATUS" => $store_auth,
"U_STORE_NAME" => append_sid("adr_shops.$phpEx?mode=view_store_admin"),
));
$i++;
}
while ( $row = $db->sql_fetchrow($result) );
}
}
$template->assign_vars(array(
"L_STORE_NAME" => $lang['Adr_store_name'],
"L_STORE_DESC" => $lang['Adr_store_desc'],
"L_STORE_IMG" => $lang['Adr_store_img'],
"L_STORE_STATUS" => $lang['Adr_store_status'],
"L_STORE_ADMIN" => $lang['Adr_store_admin']
));
break;
case 'view_store' :
$template->assign_block_vars('view_store',array());
// Prevents blank page
if ( !$shop_id ) $shop_id = 1;
if(($shop_id != '0') && ($shop_id != '2'))
$template->assign_block_vars('view_store.forum_shops', array());
// Since this is not the admin store let's show the my points view
$template->assign_block_vars('view_store.my_points', array());
// Prevent unauthorised access to admin only store
if(($userdata['user_level'] != ADMIN) && ($shop_id == '2')){
// Send admin alert of invalid user attempt
$subject = $lang['Adr_report_pm_sub'];
$message = sprintf($lang['Adr_report_pm_msg'], $character_id);
adr_send_pm('2', $subject, $message);
adr_previous(Adr_admin_only_area, 'adr_shops', '');
}
$sql = "SELECT * FROM " . ADR_STORES_TABLE . "
WHERE store_id = $shop_id ";
$result = $db->sql_query($sql);
if( !$result )
{
message_die(GENERAL_ERROR, 'Could not obtain shops information', "", __LINE__, __FILE__, $sql);
}
$row = $db->sql_fetchrow($result);
$store_name = adr_get_lang($row['store_name']);
$store_desc = adr_get_lang($row['store_desc']);
$shop_owner_id = $row['store_owner_id'];
if ( !$row['store_status'] )
{
adr_previous ( Adr_store_closed_msg , 'adr_shops' , '' );
}
if ( isset($_GET['mode2']) || isset($_POST['mode2']) )
{
$mode2 = ( isset($_POST['mode2']) ) ? htmlspecialchars($_POST['mode2']) : htmlspecialchars($_GET['mode2']);
}
else
{
$mode2 = 'itemname';
}
if(isset($_POST['order']))
{
$sort_order = ($_POST['order'] == 'ASC') ? 'ASC' : 'DESC';
}
else if(isset($_GET['order']))
{
$sort_order = ($_GET['order'] == 'ASC') ? 'ASC' : 'DESC';
}
else
{
$sort_order = 'ASC';
}
if ( isset($_GET['cat']) || isset($_POST['cat']) )
{
$cat = ( isset($_POST['cat']) ) ? htmlspecialchars($_POST['cat']) : htmlspecialchars( $_GET['cat']);
}
else
{
$cat = 0;
}
$cat_sql = ( $cat ) ? 'AND i.item_type_use = '.$cat : '';
$categories_text = array();
$categories = array();
$categories_cat = array();
adr_get_item_type_categories();
$select_category = '<select name="cat">';
for($i = 0; $i < count($categories_text); $i++)
{
if($prev_cat != $categories_cat[$i]) $select_category .= '<option style="font-weight:bold;color:black" disabled>' . adr_get_lang($categories_cat[$i]) . '</option>';
$selected = ( $cat == $categories[$i] ) ? ' selected="selected"' : '';
$select_category .= '<option value="' . $categories[$i] . '"' . $selected . '>' . adr_get_lang($categories_text[$i]) . '</option>';
$prev_cat = $categories_cat[$i];
}
$select_category .= '</select>';
$mode_types_text = array( $lang['Adr_shops_categories_item_name'] , $lang['Adr_items_price'] , $lang[ 'Adr_items_type_use'] , $lang['Adr_items_quality'] , $lang['Adr_items_power'] );
$mode_types = array( 'name', 'price' , 'type' , 'quality' , 'power' );
$select_sort_mode = '<select name="mode2">';
for($i = 0; $i < count($mode_types_text); $i++)
{
$selected = ( $mode2 == $mode_types[$i] ) ? ' selected="selected"' : '';
$select_sort_mode .= '<option value="' . $mode_types[$i] . '"' . $selected . '>' . $mode_types_text[$i] . '</option>';
}
$select_sort_mode .= '</select>';
$select_sort_order = '<select name="order">';
if($sort_order == 'ASC')
{
$select_sort_order .= '<option value="ASC" selected="selected">' . $lang['Sort_Ascending'] . '</ option><option value="DESC">' . $lang['Sort_Descending'] . '</option>';
}
else
{
$select_sort_order .= '<option value="ASC">' . $lang['Sort_Ascending'] . '</option><option value="DESC" selected="selected">' . $lang['Sort_Descending'] . '</option>';
}
$select_sort_order .= '</select>';
switch( $mode2 )
{
case 'name':
$order_by = "i.item_name $sort_order LIMIT $start, " . $board_config['topics_per_page'];
break;
case 'price':
$order_by = "i.item_price $sort_order LIMIT $start, " . $board_config['topics_per_page'];
break;
case 'type':
$order_by = "i.item_type_use $sort_order LIMIT $start, " . $board_config['topics_per_page'];
break;
case 'quality':
$order_by = "i.item_quality $sort_order LIMIT $start, " . $board_config['topics_per_page'];
break;
case 'power':
$order_by = "i.item_power $sort_order LIMIT $start, " . $board_config['topics_per_page'];
break;
default:
$order_by = "i.item_name $sort_order LIMIT $start, " . $board_config['topics_per_page'];
break;
}
##=== START: show all items or just those available to user?
$show_only_mine = intval($_GET['show_only_mine']);
$show_type = ($show_only_mine == '1') ? $lang['Adr_show_all'] : $lang['Adr_show_only_mine'];
if($show_only_mine == '1') $show_link = append_sid("adr_shops.$phpEx?mode=view_store&shop_id=".$shop_id."");
else $show_link = append_sid("adr_shops.$phpEx?mode=view_store&shop_id=".$shop_id."&show_only_mine=1");
$points_check_sql = ($show_only_mine == '1') ? ' AND i.item_price <= '.$points : '';
$item_sql = ($show_only_mine == '1') ? $item_sql : '';
##=== END: show all items or just those available to user?
$shop_more_sql = ( $shop_owner_id != 1 ) ? 'AND i.item_in_shop = 1' : '';
$sql = "SELECT i.* , q.item_quality_lang , t.item_type_lang FROM " . ADR_SHOPS_ITEMS_TABLE . " i
LEFT JOIN " . ADR_SHOPS_ITEMS_QUALITY_TABLE . " q ON ( i.item_quality = q.item_quality_id )
LEFT JOIN " . ADR_SHOPS_ITEMS_TYPE_TABLE . " t ON ( i.item_type_use = t.item_type_id )
WHERE i.item_store_id = $shop_id
AND i.item_owner_id = $shop_owner_id
AND i.item_auth = 0
$item_sql
$points_check_sql
$shop_more_sql
$cat_sql
ORDER BY $order_by";
if( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Could not query users', '', __LINE__, __FILE__, $sql);