-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathcards.php
877 lines (748 loc) · 34.1 KB
/
cards.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
<?php
require(AppSettings::srcPath().'/includes/connect.php');
require(AppSettings::srcPath().'/includes/get_session.php');
$pagetitle = "My Cards";
$nav_tab_selected = "cards";
$nav_subtab_selected = "cards";
if (!$thisuser) {
include(AppSettings::srcPath()."/includes/html_start.php");
?>
<div class="container-fluid">
<?php
if (empty($_REQUEST['redirect_key'])) $redirect_url = $app->get_redirect_url($_SERVER['REQUEST_URI']);
include(AppSettings::srcPath()."/includes/html_register.php");
?>
</div>
<?php
include(AppSettings::srcPath()."/includes/html_stop.php");
die();
}
if (!empty($_REQUEST['action'])) {
$action = $_REQUEST['action'];
$this_peer = $app->get_peer_by_server_name(AppSettings::getParam('base_url'), true);
if ($action == "create") {
$nav_subtab_selected = "create";
}
else if ($action == "manage") {
$nav_subtab_selected = "manage";
}
if ($app->synchronizer_ok($thisuser, $_REQUEST['synchronizer_token'])) {
if ($action == "try_print") {
$denomination_id = (int) $_REQUEST['cards_denomination_id'];
$denomination = $app->run_query("SELECT * FROM card_currency_denominations WHERE denomination_id=:denomination_id;", ['denomination_id' => $denomination_id])->fetch();
if ($denomination) {
$cards_account_id = (int) $_REQUEST['cards_account_id'];
$currency_account = $app->fetch_account_by_id($cards_account_id);
if ($currency_account) {
if ($currency_account['user_id'] == $thisuser->db_user['user_id']) {
$db_currency = $app->fetch_currency_by_id($denomination['currency_id']);
$fv_currency = $app->fetch_currency_by_id($denomination['fv_currency_id']);
$fv_blockchain = new Blockchain($app, $fv_currency['blockchain_id']);
$how_many = intval($_REQUEST['cards_howmany']);
if ($_REQUEST['cards_howmany'] == "other") $how_many = intval($_REQUEST['cards_howmany_other_val']);
if ($how_many > 0) {
$cost = $how_many*$denomination['denomination']*pow(10, $fv_blockchain->db_blockchain['decimal_places']);
$fee = (int) (0.0001*pow(10, $fv_blockchain->db_blockchain['decimal_places']));
$account_balance = $fv_blockchain->account_balance($currency_account['account_id']);
if ($cost+$fee <= $account_balance) {
$io_ids = [];
$input_sum = 0;
$first_address_id = false;
$keep_looping = true;
$balance_r = $app->run_query("SELECT io.* FROM transaction_ios io JOIN transactions t ON io.create_transaction_id=t.transaction_id JOIN addresses a ON io.address_id=a.address_id JOIN address_keys k ON a.address_id=k.address_id WHERE k.account_id=:account_id AND io.spend_status='unspent';", [
'account_id' => $currency_account['account_id']
]);
while ($keep_looping && $io = $balance_r->fetch()) {
array_push($io_ids, $io['io_id']);
if (empty($first_address_id)) $first_address_id = $io['address_id'];
$input_sum += $io['amount'];
if ($input_sum >= $cost+$fee) $keep_looping = false;
}
$output_amounts = [];
$output_address_ids = [];
for ($i=0; $i<$how_many; $i++) {
$address_key = $app->new_address_key($fv_currency['currency_id'], $currency_account);
array_push($output_amounts, $denomination['denomination']*pow(10, $fv_blockchain->db_blockchain['decimal_places']));
array_push($output_address_ids, $address_key['address_id']);
}
if ($cost+$fee < $input_sum) {
array_push($output_amounts, $input_sum-$cost-$fee);
array_push($output_address_ids, $first_address_id);
}
$error_message = false;
$transaction_id = $fv_blockchain->create_transaction("transaction", $output_amounts, false, $io_ids, $output_address_ids, $fee, $error_message);
if ($transaction_id) {
$db_transaction = $app->fetch_transaction_by_id($transaction_id);
$name = $_REQUEST['cards_name'];
$title = $_REQUEST['cards_title'];
$email = $_REQUEST['cards_email'];
$pnum = $_REQUEST['cards_pnum'];
$purity = $_REQUEST['cards_purity'];
$new_card_params = [
'image_id' => $db_currency['default_design_image_id'],
'denomination_id' => $denomination['denomination_id'],
'purity' => $purity,
'display_name' => $name,
'display_title' => $title,
'display_email' => $email,
'display_pnum' => $pnum,
'time_created' => time(),
'user_id' => $thisuser->db_user['user_id'],
'redeem_url' => AppSettings::getParam('base_url'),
'text_color' => empty($fv_currency['default_design_text_color']) ? null : $fv_currency['default_design_text_color']
];
$app->run_insert_query("card_designs", $new_card_params);
$design_id = $app->last_insert_id();
$app->run_insert_query("card_printrequests", [
'secrets_present' => 1,
'print_status' => 'not-printed',
'pay_status' => 'not-received',
'peer_id' => $this_peer['peer_id'],
'design_id' => $design_id,
'user_id' => $thisuser->db_user['user_id'],
'how_many' => $how_many,
'time_created' => time()
]);
$request_id = $app->last_insert_id();
$paper_width = "";
if (!empty($_REQUEST['paper_width'])) $paper_width = $_REQUEST['paper_width'];
if (empty($paper_width)) $paper_width = "standard";
else if ($paper_width == "small") {}
$max_id = $app->run_query("SELECT MAX(peer_card_id), MAX(group_id) FROM cards WHERE peer_id=:peer_id;", ['peer_id' => $this_peer['peer_id']])->fetch();
$card_group_id = $max_id[1]+1;
$first_id = 1;
if ($max_id[0] > 0) $first_id = $max_id[0]+1;
for ($i=0; $i<$how_many; $i++) {
$card_id = $i+$first_id;
$secret = $app->random_number(16);
$secret_hash = $app->card_secret_to_hash($secret);
$app->run_insert_query("cards", [
'design_id' => $design_id,
'status' => 'issued',
'peer_id' => $this_peer['peer_id'],
'purity' => $purity,
'group_id' => $card_group_id,
'secret' => $secret,
'secret_hash' => $secret_hash,
'peer_card_id' => $card_id,
'mint_time' => time(),
'currency_id' => $db_currency['currency_id'],
'fv_currency_id' => $fv_currency['currency_id'],
'amount' => $denomination['denomination'],
'io_tx_hash' => $db_transaction['tx_hash'],
'io_out_index' => $i
]);
}
$app->run_query("UPDATE card_printrequests SET card_group_id=:card_group_id WHERE request_id=:request_id;", [
'card_group_id' => $card_group_id,
'request_id' => $request_id
]);
$app->run_query("UPDATE card_designs SET status='printed' WHERE design_id=:design_id;", [
'design_id' => $design_id
]);
$error_message = $how_many." cards have been created, next please <a href=\"/cards/?action=print_design&design_id=".$design_id."\">download the PDFs</a> or <a href=\"/explorer/blockchains/".$fv_blockchain->db_blockchain['url_identifier']."/transactions/".$db_transaction['tx_hash']."\">view the transaction</a>.<br/>\n";
$error_class = "error";
$action = "manage";
$nav_subtab_selected = "manage";
}
else {
$error_message = "Payment error: failed to create a transaction on the blockchain.";
$error_class = "error";
}
}
else {
$error_message = "Payment error: the account you selected cannot afford to generate these cards.";
$error_class = "error";
}
}
else {
$error_message = "Error: invalid quantity of cards.";
$error_class = "error";
}
}
else {
$error_message = "Error: you don't have permission to perform this action.";
$error_class = "error";
}
}
else {
$error_message = "Error: invalid account selected.";
$error_class = "error";
}
}
else {
$error_message = "Error: invalid denomination.";
$error_class = "error";
}
}
if ($action == "print_design") {
$design_id = (int) $_REQUEST['design_id'];
$design = $app->run_query("SELECT * FROM card_designs d JOIN card_printrequests r ON r.design_id=d.design_id JOIN users u ON d.user_id=u.user_id WHERE d.design_id=:design_id;", [
'design_id' => $design_id
])->fetch();
if ($design) {
if ($design['user_id'] == $thisuser->db_user['user_id']) {
$paper_width = "";
if (!empty($_REQUEST['paper_width'])) $paper_width = $_REQUEST['paper_width'];
if (empty($paper_width)) $paper_width = "standard";
else if ($paper_width == "small") {}
$card_group_id = $design['card_group_id'];
$from = $app->run_query("SELECT MIN(card_id) FROM cards WHERE design_id=:design_id;", ['design_id' => $design['design_id']])->fetch()[0];
if (empty($from)) die("Error, the cards haven't been created yet.");
$to = $from + $design['how_many'] - 1;
require_once(AppSettings::srcPath().'/lib/card-render/fpdf.php');
$perpage = 10;
$numcards = $to-$from+1;
$numpages = ceil($numcards/$perpage);
if ($paper_width == "small") {
$pdf = new FPDF('P','in',array(2.4,3.5*5+0.5));
$orient = "tall";
$card_print_width = 2;
}
else {
$pdf = new FPDF('P','in',array(8.5,11));
$orient = "fat";
$card_print_width = 3.5;
}
$these_cards = $app->run_query("SELECT * FROM cards WHERE card_id >= :from_card_id AND card_id <= :to_card_id;", [
'from_card_id' => $from,
'to_card_id' => $to
]);
$count = 0;
$res = "";
if (!empty($_REQUEST['res'])) {
$res = $_REQUEST['res'];
if ($res != "low") $res = "high";
}
if ($res == "low") $extension = "jpg";
else $extension = "png";
for ($dubpage=1; $dubpage<=$numpages; $dubpage++) {
$numthispage = 10;
if ($count+$numthispage > $numcards) $numthispage = $numcards-$count;
$cardarr = [];
for ($pos=1; $pos <= $numthispage; $pos++) {
$cardarr[$pos-1] = $these_cards->fetch();
$count++;
}
if ($paper_width != "small") {
$pdf->AddPage();
$pdf->Line(0, 0.5, 0.25, 0.5);
$pdf->Line(8.25, 0.5, 8.5, 0.5);
$pdf->Line(0.75, 0, 0.75, 0.25);
$pdf->Line(7.75, 0, 7.75, 0.25);
$pdf->Line(4.25, 0, 4.25, 0.25);
for ($pos=1; $pos <= $numthispage; $pos++) {
$front_coords = $app->position_by_pos($pos, 'front', $paper_width);
$side = "front";
$temp_render_url = AppSettings::getParam('base_url')."/lib/card-render/render".$side.".php?key=".AppSettings::getParam('operator_key')."&card_id=".$cardarr[$pos-1]['card_id']."&orient=".$orient."&res=".$res;
$pdf->Image($temp_render_url, $front_coords[0], $front_coords[1], $card_print_width, false, 'png');
}
$pdf->Line(0, 10.5, 0.25, 10.5);
$pdf->Line(8.25, 10.5, 8.5, 10.5);
$pdf->Line(0.75, 11, 0.75, 10.75);
$pdf->Line(7.75, 11, 7.75, 10.75);
$pdf->Line(4.25, 10.75, 4.25, 11);
}
$pdf->AddPage();
$pdf->Line(0, 0.5, 0.25, 0.5);
$pdf->Line(8.25, 0.5, 8.5, 0.5);
$pdf->Line(0.75, 0, 0.75, 0.25);
$pdf->Line(7.75, 0, 7.75, 0.25);
$pdf->Line(4.25, 0, 4.25, 0.25);
for ($pos=1; $pos <= $numthispage; $pos++) {
$back_coords = $app->position_by_pos($pos, 'back', $paper_width);
$side = "back";
$img_png_url = AppSettings::getParam('base_url')."/lib/card-render/render".$side.".php?key=".AppSettings::getParam('operator_key')."&card_id=".$cardarr[$pos-1]['card_id']."&orient=".$orient."&res=".$res;
$pdf->Image($img_png_url, $back_coords[0], $back_coords[1], $card_print_width, false, 'png');
}
$pdf->Line(0, 10.5, 0.25, 10.5);
$pdf->Line(8.25, 10.5, 8.5, 10.5);
$pdf->Line(0.75, 11, 0.75, 10.75);
$pdf->Line(7.75, 11, 7.75, 10.75);
$pdf->Line(4.25, 10.75, 4.25, 11);
}
$app->run_query("UPDATE card_printrequests SET print_status='printed' WHERE request_id=:request_id;", [
'request_id' => $design['request_id']
]);
$pdf->Output('cards'.$from.'_'.$to.'.pdf', "D");
die();
}
else {
$error_message = "Error, you don't have permission to perform this action.";
$error_class = "error";
}
}
else {
$error_message = "Error, invalid denomination or number of cards.";
$error_class = "error";
}
$action = "manage";
$nav_subtab_selected = "manage";
}
else if ($action == "activate_cards") {
$printrequest = $app->run_query("SELECT * FROM card_printrequests pr JOIN card_designs d ON pr.design_id=d.design_id WHERE pr.request_id=:request_id;", [
'request_id' => $_REQUEST['printrequest_id']
])->fetch();
if ($printrequest) {
if ($printrequest['user_id'] == $thisuser->db_user['user_id']) {
$card_arr = $app->run_query("SELECT * FROM card_printrequests pr JOIN card_designs d ON pr.design_id=d.design_id JOIN cards c ON c.design_id=d.design_id WHERE pr.request_id=:request_id ORDER BY c.card_id ASC;", ['request_id' => $printrequest['request_id']])->fetchAll();
$change_count = 0;
if (count($card_arr) > 0) {
foreach ($card_arr as $card) {
if (in_array($card['status'], array('issued','printed','assigned'))) {
$app->change_card_status($card, 'sold');
$change_count++;
}
}
$error_message = $change_count." cards have been activated.";
$error_class = "success";
}
}
}
$action = "manage";
$nav_subtab_selected = "manage";
}
else if ($action == "wipe_secrets") {
$printrequest = $app->run_query("SELECT * FROM card_printrequests pr JOIN card_designs d ON pr.design_id=d.design_id WHERE pr.request_id=:request_id;", ['request_id'=>$_REQUEST['printrequest_id']])->fetch();
if ($printrequest) {
if ($printrequest['secrets_present'] == 1) {
$app->run_query("UPDATE cards SET secret=NULL WHERE group_id=:group_id;", [
'group_id' => $printrequest['card_group_id']
]);
$app->run_query("UPDATE card_printrequests SET secrets_present=0 WHERE request_id=:request_id;", ['request_id'=>$printrequest['request_id']]);
$error_message = "Secrets have been successfully wiped for this card group!";
$error_class = "success";
}
else {
$error_message = "Action canceled: secrets have already been wiped.";
$error_class = "error";
}
}
else {
$error_message = "Error: invalid print request ID.";
$error_class = "error";
}
$action = "manage";
$nav_subtab_selected = "manage";
}
else if ($action == "change_card_status") {
$card_id = (int) $_REQUEST['card_id'];
$to_status = $_REQUEST['to_status'];
$card = $app->run_query("SELECT *, pr.user_id AS user_id FROM card_printrequests pr JOIN card_designs d ON pr.design_id=d.design_id JOIN cards c ON c.design_id=d.design_id WHERE c.card_id=:card_id;", ['card_id'=>$card_id])->fetch();
if ($card) {
if ($card['user_id'] == $thisuser->db_user['user_id']) {
$ok = false;
if ($card['status'] == "sold" && ($to_status == "canceled" || $to_status == "printed")) $ok = true;
else if (in_array($card['status'], array("printed", "issued")) && in_array($to_status, array('canceled','sold'))) $ok = true;
if ($ok) {
$app->change_card_status($card, $to_status);
$error_message = "Successfully changed status of <a href=\"/redeem/".$card['card_id']."\">card #".$card['card_id']."</a>";
$error_class = "success";
}
else {
$error_message = "You can't switch this card to that status.";
$error_class = "error";
}
}
else {
$error_message = "Permission denied.";
$error_class = "error";
}
}
else {
$error_message = "Failed to change card status: invalid card ID.";
$error_class = "error";
}
}
else if ($action == "import_cards") {
$peer_name = urldecode($_REQUEST['peer_name']);
$from_card_id = (int) $_REQUEST['from_card_id'];
$to_card_id = (int) $_REQUEST['to_card_id'];
if ($peer_name[strlen($peer_name)-1] == "/") $peer_name = substr($peer_name, 0, strlen($peer_name)-1);
$peer = $app->get_peer_by_server_name($peer_name, false);
$add_count = 0;
if ($peer) {
$remote_url = $peer_name."/api/cards/".$from_card_id."-".$to_card_id;
$remote_response = get_object_vars(json_decode(file_get_contents($remote_url)));
$card_public_vars = $app->card_public_vars();
if (!empty($remote_response) && count($remote_response['cards']) > 0) {
for ($i=0; $i<count($remote_response['cards']); $i++) {
$import_card = get_object_vars($remote_response['cards'][$i]);
$existing_card = $app->fetch_card_by_peer_and_id($peer['peer_id'], $import_card['peer_card_id']);
if (!$existing_card) {
$fv_currency = $app->get_currency_by_abbreviation($import_card['currency_abbreviation']);
$currency = $app->get_currency_by_abbreviation($import_card['fv_currency_abbreviation']);
$new_card_params = [
'peer_id' => $peer['peer_id'],
'currency_id' => $currency['currency_id'],
'fv_currency_id' => $fv_currency['currency_id']
];
for ($j=0; $j<count($card_public_vars); $j++) {
$new_card_params[$card_public_vars[$j]] = $import_card[$card_public_vars[$j]];
}
$app->run_insert_query("cards", $new_card_params);
$add_count++;
}
}
}
}
$error_message = $add_count." cards have been imported.";
$error_class = "error";
$action = "manage";
$nav_subtab_selected = "manage";
}
}
}
$my_cards = $app->run_query("SELECT c.*, u.*, curr.*, c.amount AS amount FROM cards c JOIN card_users u ON c.card_id=u.card_id JOIN currencies curr ON c.fv_currency_id=curr.currency_id WHERE c.user_id=:user_id;", ['user_id'=>$thisuser->db_user['user_id']])->fetchAll();
include(AppSettings::srcPath().'/includes/html_start.php');
?>
<div class="container-fluid">
<?php
if (!empty($error_message)) echo $app->render_error_message($error_message, $error_class);
$btc_currency = $app->get_currency_by_abbreviation("btc");
$btc_usd_price = $app->latest_currency_price($btc_currency['currency_id']);
if ($nav_subtab_selected == "create") {
?>
<script type="text/javascript">
thisPageManager.card_printing_cost = 0.25;
thisPageManager.cost_per_coin = 1;
thisPageManager.coin_abbreviation = "";
thisPageManager.usd_per_btc = <?php if ($btc_usd_price) echo $btc_usd_price['price']; else echo "false"; ?>;
window.onload = function() {
thisPageManager.cards_howmany_changed();
thisPageManager.fv_currency_id_changed();
};
</script>
<div class="panel panel-info" style="margin-top: 15px;">
<div class="panel-heading">
<div class="panel-title">Create Cards</div>
</div>
<div class="panel-body">
<form action="/cards/" method="post">
<input type="hidden" name="action" value="try_print" />
<input type="hidden" name="cards_payment_amount" id="payment_amount" value="" />
<input type="hidden" name="synchronizer_token" value="<?php echo $thisuser->get_synchronizer_token(); ?>" />
<div class="form-group">
<label for="cards_currency_id">Which currency should the cards convert to?</label>
<select id="cards_currency_id" class="form-control" name="cards_currency" onchange="thisPageManager.currency_id_changed();">
<option value="">-- Please Select --</option>
<?php
$blockchain_currencies = $app->run_query("SELECT * FROM currencies WHERE blockchain_id IS NOT NULL ORDER BY name ASC;");
while ($currency = $blockchain_currencies->fetch()) {
echo "<option value=\"".$currency['currency_id']."\">".$currency['name']."</option>\n";
}
?>
</select>
</div>
<div class="form-group">
<label for="cards_fv_currency_id">Which currency should the cards hold?</label>
<select id="cards_fv_currency_id" class="form-control" name="cards_fv_currency_id" onchange="thisPageManager.fv_currency_id_changed();">
<option value="">-- Please Select --</option>
</select>
</div>
<div class="form-group">
<label for="cards_account_id">Which account should pay for these cards?</label>
<select id="cards_account_id" class="form-control" name="cards_account_id">
<option value="">-- Please Select --</option>
</select>
</div>
<div class="form-group">
<label for="cards_denomination_id">What denomination should the cards be?</label>
<select id="cards_denomination_id" class="form-control" name="cards_denomination_id">
<option value="">-- Please Select --</option>
</select>
</div>
<div class="form-group">
<label for="cards_howmany">How many cards do you want to print?</label>
<select id="cards_howmany" class="form-control" name="cards_howmany" onchange="thisPageManager.cards_howmany_changed();">
<?php
$ops = ['10','20','50','100','other'];
for ($i=0; $i<count($ops); $i++) {
echo "<option value=\"".$ops[$i]."\">";
if ($ops[$i] == "other") echo "Other";
else echo $ops[$i]." cards";
echo "</option>\n";
}
?>
</select>
</div>
<div class="form-group" style="display: none;" id="cards_howmany_other">
<label for="cards_howmany_other_val">How many?</label>
<input type="text" class="form-control" size="4" value="" id="cards_howmany_other_val" name="cards_howmany_other_val" placeholder="100" /> cards
</div>
<div class="form-group">
<label for="card_purity">How much should be charged in fees to the person redeeming each card?</label>
<div id="cards_purity_btc" style="display: none;">
0.00%
</div>
<div id="cards_purity_usd">
<select id="cards_purity" class="form-control" name="cards_purity">
<?php
$ops = ['100','95','92','90','88','85','80'];
for ($i=0; $i<count($ops); $i++) {
echo "<option ";
if ($ops[$i] == 100) echo "selected=\"selected\" ";
echo "value=\"".$ops[$i]."\">";
if ($ops[$i] == "unspecified") echo "Unspecified";
else echo (100-$ops[$i])."% in fees";
echo "</option>\n";
}
?>
</select>
</div>
</div>
<div class="form-group">
<label for="cards_name">Please enter a name that you would like to appear on the cards:</label>
<input type="text" size="50" id="cards_name" class="form-control" name="cards_name" />
</div>
<div class="form-group">
<label for="cards_title">(Optional) Please enter a position & title to appear on the cards:</label>
<input type="text" size="70" id="cards_title" class="form-control" name="cards_title" />
</div>
<div class="form-group">
<label for="cards_email">(Optional) Please an email address that you would like to appear on the cards:</label>
<input type="text" size="40" id="cards_email" class="form-control" name="cards_email" />
</div>
<div class="form-group">
<label for="cards_pnum">(Optional) Please enter a phone number that you would like to appear on the cards:</label>
<input type="text" size="40" id="cards_pnum" class="form-control" name="cards_pnum" />
</div>
<a href="" onclick="thisPageManager.show_card_preview(); return false;">Preview my cards</a><br/>
<div id="cards_preview" style="display: none; padding: 5px;"> </div>
<br/>
<input class="btn btn-primary" type="submit" value="Save & Continue" />
</form>
</div>
</div>
<?php
}
else if ($nav_subtab_selected == "manage") {
$my_printrequests = $app->run_query("SELECT * FROM card_printrequests pr JOIN card_designs cd ON pr.design_id=cd.design_id JOIN card_currency_denominations denom ON cd.denomination_id=denom.denomination_id JOIN currencies c ON denom.currency_id=c.currency_id WHERE pr.user_id=:user_id ORDER BY pr.time_created DESC;", ['user_id'=>$thisuser->db_user['user_id']])->fetchAll();
echo '
<div class="panel panel-info" style="margin-top: 15px;">
<div class="panel-heading">
<div class="panel-title">My Print Requests ('.count($my_printrequests).')</div>
</div>
<div class="panel-body">';
foreach ($my_printrequests as $printrequest) {
$peer = $app->fetch_peer_by_id($printrequest['peer_id']);
$minmax = $app->run_query("SELECT MIN(card_id), MAX(card_id), MIN(peer_card_id), MAX(peer_card_id) FROM cards WHERE group_id=:group_id;", [
'group_id' => $printrequest['card_group_id']
])->fetch();
echo "<div class=\"row\">";
echo "<div class=\"col-sm-4\">".$peer['peer_name']." cards ".$minmax['MIN(peer_card_id)'].":".$minmax['MAX(peer_card_id)']." ".$printrequest['how_many']." ✗ ".$printrequest['denomination']." ".$printrequest['short_name']." cards</div>";
echo "<div class=\"col-sm-4\">".$printrequest['display_name'].", ".$printrequest['display_email']."</div>\n";
echo "<div class=\"col-sm-4\">";
echo "<a href=\"/cards/?action=activate_cards&printrequest_id=".$printrequest['request_id']."\">Activate Cards</a>\n";
if ($printrequest['secrets_present'] == 1) {
echo " <a href=\"/cards/?action=print_design&design_id=".$printrequest['design_id']."\">Download PDFs</a>\n";
echo " <a href=\"/cards/?action=wipe_secrets&printrequest_id=".$printrequest['request_id']."\">Wipe Secrets</a>\n";
}
echo "</div>\n";
echo "</div>\n";
}
echo "</div></div>\n";
$my_cards_arr = $app->run_query("SELECT * FROM card_printrequests pr JOIN card_designs cd ON pr.design_id=cd.design_id JOIN card_currency_denominations denom ON cd.denomination_id=denom.denomination_id JOIN currencies c ON denom.currency_id=c.currency_id JOIN cards ON cards.design_id=cd.design_id WHERE pr.user_id=:user_id ORDER BY cards.card_id ASC;", ['user_id'=>$thisuser->db_user['user_id']])->fetchAll();
echo '
<div class="panel panel-info" style="margin-top: 15px;">
<div class="panel-heading">
<div class="panel-title">My Cards ('.count($my_cards_arr).')</div>
</div>
<div class="panel-body">';
foreach ($my_cards_arr as $db_card) {
echo '<div class="card_small">';
echo '<a target="_blank" href="/redeem/'.$db_card['peer_id'].'/'.$db_card['peer_card_id'].'">'.$db_card['peer_card_id']."</a><br/>\n";
echo " ".$app->format_bignum($db_card['amount'])." ".$db_card['abbreviation'];
echo "<br/>";
echo $db_card['status'];
echo "</div>\n";
}
echo "</div></div>\n";
?>
<div class="panel panel-info">
<div class="panel-heading">
<div class="panel-title">Import Cards</div>
</div>
<div class="panel-body">
<p>
To import cards from a remote card peer, please enter the peer's website URL and the range of card IDs that you wish to import.
</p>
<form action="/cards/" method="get">
<input type="hidden" name="action" value="import_cards" />
<div class="form-group">
<label for="peer_name">From website:</label>
<input type="text" class="form-control" name="peer_name" placeholder="http://" />
</div>
<div class="form-group">
<label for="from_card_id">From card ID:</label>
<input type="text" class="form-control" name="from_card_id" />
</div>
<div class="form-group">
<label for="to_card_id">To card ID:</label>
<input type="text" class="form-control" name="to_card_id" />
</div>
<input type="submit" class="btn btn-primary" value="Import Cards" />
</form>
</div>
</div>
<?php
}
else {
if (empty($my_cards)) $my_cards = [];
$reference_currency = $app->get_reference_currency();
$btc_currency = $app->get_currency_by_abbreviation('btc');
$currency_prices = $app->fetch_currency_prices();
if (empty($my_cards)) $networth = 0;
else $networth = $app->calculate_cards_networth($my_cards);
if (empty($_REQUEST['start_section'])) $_REQUEST['start_section'] = "cards";
if (in_array($_REQUEST['start_section'], ['cards', 'add_card', 'withdraw_btc'])) {
?>
<script type="text/javascript">
window.onload = function() {
thisPageManager.open_page_section(<?php echo "'".$_REQUEST['start_section']."'"; ?>);
};
</script>
<?php
}
?>
<div id="section_cards" style="display: none; margin-top: 15px;">
<div class="panel panel-info">
<div class="panel-heading">
<div class="panel-title">My Cards</div>
</div>
<div class="panel-body">
<?php
echo "You have ".count($my_cards)." card";
if (count($my_cards) != 1) echo "s";
echo " in this user account. ";
if (count($my_cards) > 1) {
?>
<div id="display_hotcards">
<?php
for ($i=0; $i<count($my_cards); $i++) {
echo '<div class="card_small" id="card_btn'.$i.'" onclick="thisPageManager.open_card('.$i.');">';
if ($my_cards[$i]['status'] == "claimed") echo "<b>";
echo $my_cards[$i]['peer_card_id'];
echo "<br/>\n";
echo $app->format_bignum($my_cards[$i]['amount'])." ".$my_cards[$i]['abbreviation'];
if ($my_cards[$i]['status'] == "claimed") echo "</b>";
echo "</div>\n";
}
?>
</div>
<br/>
<?php
}
?>
<div><?php
if (!empty($my_cards)) {
for ($i=0; $i<count($my_cards); $i++) {
?>
<div class="card_block" id="card_block<?php echo $i; ?>" style="display: none;">
<div style="display: block; overflow: hidden;">
<div class="row">
<div class="col-xs-4">peer</div><div class="col-xs-8"><?php
$peer = $app->fetch_peer_by_id($my_cards[$i]['peer_id']);
echo $peer['peer_identifier'];
?></div>
</div>
<div class="row">
<div class="col-xs-4">Card ID</div><div class="col-xs-8">#<?php echo $my_cards[$i]['peer_card_id']; ?></div>
</div>
<div class="row">
<div class="col-xs-4">Minted</div><div class="col-xs-8"><?php echo $app->format_seconds(time() - $my_cards[$i]['mint_time']); ?> ago</div>
</div>
<div class="row">
<div class="col-xs-4">Card denomination</div>
<div class="col-xs-8 greentext">
<?php
echo $app->format_bignum($my_cards[$i]['amount'])." ".$my_cards[$i]['abbreviation'];
?>
</div>
</div>
<div class="row">
<div class="col-xs-4">Status</div>
<div class="col-xs-8">
<?php
echo ucwords($my_cards[$i]['status']);
?>
</div>
</div>
<?php
if ($my_cards[$i]['purity'] != 100) { ?>
<div class="row">
<div class="col-xs-4">Fees</div>
<div class="col-xs-8" style="color: #<?php
$fees = $app->get_card_fees($my_cards[$i]);
if ($fees > 0) echo "f00"; else echo "0a0;";
?>"><?php echo $app->format_bignum($fees)." ".$my_cards[$i]['abbreviation']; ?>
</div>
</div>
<?php
}
$fv_currency = $app->fetch_currency_by_id($my_cards[$i]['fv_currency_id']);
if ($my_cards[$i]['status'] == "claimed") {
?>
<p style="margin-top: 15px;">
<button class="btn btn-success" onclick="thisPageManager.card_id=<?php echo $my_cards[$i]['peer_card_id']; ?>; thisPageManager.peer_id=<?php echo $my_cards[$i]['peer_id']; ?>; $('#claim_dialog').modal('show');">Withdraw to Address</button>
<button id="claim_account_btn_<?php echo $my_cards[$i]['peer_card_id'].'_'.$my_cards[$i]['peer_id']; ?>" class="btn btn-primary" onclick="thisPageManager.card_id=<?php echo $my_cards[$i]['peer_card_id']; ?>; thisPageManager.peer_id=<?php echo $my_cards[$i]['peer_id']; ?>; thisPageManager.claim_card('to_account');">Withdraw to Account</button>
<button id="claim_game_btn_<?php echo $my_cards[$i]['peer_card_id'].'_'.$my_cards[$i]['peer_id']; ?>" class="btn btn-info" onclick="thisPageManager.card_id=<?php echo $my_cards[$i]['peer_card_id']; ?>; thisPageManager.peer_id=<?php echo $my_cards[$i]['peer_id']; ?>; thisPageManager.claim_card('to_game');">Buy in to Game</button>
</p>
<?php
}
?>
<div id="messages" style="margin-top: 15px; display: block;"></div>
</div>
</div>
<?php
}
}
?>
</div>
</div>
</div>
</div>
<div id="claim_dialog" class="modal fade" style="display: none;">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Claim Coins</h4>
</div>
<div class="modal-body">
<div class="form-group">
<label for="claim_fee">Fee:</label>
<input class="form-control" type="tel" placeholder="0.0001" value="0.0001" id="claim_fee" style="text-align: right;" />
</div>
<div class="form-group">
<label for="claim_address">Address:</label>
<input class="form-control" type="text" id="claim_address" />
</div>
<span class="greentext" style="display: none;" id="claim_message"></span>
<button id="claim_address_btn" class="btn btn-success" onclick="thisPageManager.claim_card('to_address');">Send Coins</button>
</div>
</div>
</div>
</div>
<div id="section_add_card" style="display: none;">
<div class="panel panel-info">
<div class="panel-heading">
<div class="panel-title">Log in to a card to add it to this account</div>
</div>
<div class="panel-body">
<?php
$ask4nameid = TRUE;
$login_title = "";
$card_login_card_id = "$('#peer_card_id').val()";
$card_login_peer_id = "$('#peer_id').val()";
include(AppSettings::srcPath()."/includes/html_card_login.php");
?>
</div>
</div>
</div>
<?php
}
?>
</div>
<?php
include(AppSettings::srcPath().'/includes/html_stop.php');
?>