forked from NB-Core/lotgd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bank.php
273 lines (269 loc) · 17.4 KB
/
bank.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
<?php
// translator ready
// addnews ready
// mail ready
/**
* \file bank.php
* This file holds the entire bank code for the village bank. You can withdraw or depost gold here as user.
* @see village.php
*/
require_once("common.php");
require_once("lib/systemmail.php");
require_once("lib/sanitize.php");
require_once("lib/http.php");
require_once("lib/villagenav.php");
tlschema("bank");
page_header("Ye Olde Bank");
output("`^`c`bYe Olde Bank`b`c");
$op = httpget('op');
$point=getsetting('moneydecimalpoint',".");
$sep=getsetting('moneythousandssep',",");
if ($op==""){
checkday();
output("`6As you approach the pair of impressive carved rock crystal doors, they part to allow you entrance into the bank.");
output("You find yourself standing in a room of exquisitely vaulted ceilings of carved stone.");
output("Light filters through tall windows in shafts of soft radiance.");
output("About you, clerks are bustling back and forth.");
output("The sounds of gold being counted can be heard, though the treasure is nowhere to be seen.`n`n");
output("You walk up to a counter of jet black marble.`n`n");
output("`@Elessa`6, a petite woman in an immaculately tailored business dress, greets you from behind reading spectacles with polished silver frames.`n`n");
output("`6\"`5Greetings, my good lady,`6\" you greet her, \"`5Might I inquire as to my balance this fine day?`6\"`n`n");
output("`@Elessa`6 blinks for a moment and then smiles, \"`@Hmm, `&%s`@, let's see.....`6\" she mutters as she scans down a page in her ledger.",$session['user']['name']);
if ($session['user']['goldinbank']>=0){
output("`6\"`@Aah, yes, here we are. You have `^%s gold`@ in our prestigious bank. Is there anything else I can do for you?`6\"",number_format($session['user']['goldinbank'],0,$point,$sep));
}else{
output("`6\"`@Aah, yes, here we are. You have a `&debt`@ of `^%s gold`@ in our prestigious bank. Is there anything else I can do for you?`6\"",number_format(abs($session['user']['goldinbank']),0,$point,$sep));
}
}elseif($op=="transfer"){
output("`6`bTransfer Money`b:`n");
if ($session['user']['goldinbank']>=0){
output("`@Elessa`6 tells you, \"`@Just so that you are fully aware of our policies, you may only transfer `^%s`@ gold per the recipient's level.",getsetting("transferperlevel",25));
$maxout = $session['user']['level']*getsetting("maxtransferout",25);
output("Similarly, you may transfer no more than `^%s`@ gold total during the day.`6\"`n",$maxout);
if ($session['user']['amountouttoday'] > 0) {
output("`6She scans her ledgers briefly, \"`@For your knowledge, you have already transferred `^%s`@ gold today.`6\"`n",$session['user']['amountouttoday']);
}
output_notl("`n");
$preview = translate_inline("Preview Transfer");
rawoutput("<form action='bank.php?op=transfer2' method='POST'>");
output("Transfer how much: ");
rawoutput("<input name='amount' id='amount' width='5'>");
output_notl("`n");
output("To: ");
rawoutput("<input name='to'>");
output(" (partial names are ok, you will be asked to confirm the transaction before it occurs).`n");
rawoutput("<input type='submit' class='button' value='$preview'></form>");
rawoutput("<script language='javascript'>document.getElementById('amount').focus();</script>");
addnav("","bank.php?op=transfer2");
}else{
output("`@Elessa`6 tells you that she refuses to transfer money for someone who is in debt.");
}
}elseif($op=="transfer2"){
output("`6`bConfirm Transfer`b:`n");
$string="%";
$to = httppost('to');
for ($x=0;$x<strlen($to);$x++){
$string .= substr($to,$x,1)."%";
}
$sql = "SELECT name,login FROM " . db_prefix("accounts") . " WHERE name LIKE '".addslashes($string)."' AND locked=0 ORDER by login='$to' DESC, name='$to' DESC, login";
$result = db_query($sql);
$amt = abs((int)httppost('amount'));
if (db_num_rows($result)==1){
$row = db_fetch_assoc($result);
$msg = translate_inline("Complete Transfer");
rawoutput("<form action='bank.php?op=transfer3' method='POST'>");
output("`6Transfer `^%s`6 to `&%s`6.",$amt,$row['name']);
rawoutput("<input type='hidden' name='to' value='".HTMLEntities($row['login'], ENT_COMPAT, getsetting("charset", "ISO-8859-1"))."'><input type='hidden' name='amount' value='$amt'><input type='submit' class='button' value='$msg'></form>",true);
addnav("","bank.php?op=transfer3");
}elseif(db_num_rows($result)>100){
output("`@Elessa`6 looks at you disdainfully and coldly, but politely, suggests you try narrowing down the field of who you want to send money to just a little bit!`n`n");
$msg = translate_inline("Preview Transfer");
rawoutput("<form action='bank.php?op=transfer2' method='POST'>");
output("Transfer how much: ");
rawoutput("<input name='amount' id='amount' width='5' value='$amt'><br>");
output("To: ");
rawoutput("<input name='to' value='$to'>");
output(" (partial names are ok, you will be asked to confirm the transaction before it occurs).`n");
rawoutput("<input type='submit' class='button' value='$msg'></form>");
rawoutput("<script language='javascript'>document.getElementById('amount').focus();</script>",true);
addnav("","bank.php?op=transfer2");
}elseif(db_num_rows($result)>1){
rawoutput("<form action='bank.php?op=transfer3' method='POST'>");
output("`6Transfer `^%s`6 to ",$amt);
rawoutput("<select name='to' class='input'>");
while ($row = db_fetch_assoc($result)) {
rawoutput("<option value=\"".HTMLEntities($row['login'], ENT_COMPAT, getsetting("charset", "ISO-8859-1"))."\">".full_sanitize($row['name'])."</option>");
}
$msg = translate_inline("Complete Transfer");
rawoutput("</select><input type='hidden' name='amount' value='$amt'><input type='submit' class='button' value='$msg'></form>",true);
addnav("","bank.php?op=transfer3");
}else{
output("`@Elessa`6 blinks at you from behind her spectacles, \"`@I'm sorry, but I can find no one matching that name who does business with our bank! Please try again.`6\"");
}
}elseif($op=="transfer3"){
$amt = abs((int)httppost('amount'));
$to = httppost('to');
output("`6`bTransfer Completion`b`n");
if ($session['user']['gold']+$session['user']['goldinbank']<$amt){
output("`@Elessa`6 stands up to her full, but still diminutive height and glares at you, \"`@How can you transfer `^%s`@ gold when you only possess `^%s`@?`6\"",number_format($amt,0,$point,$sep),number_format($session['user']['gold']+$session['user']['goldinbank'],0,$point,$sep));
}else{
$sql = "SELECT name,acctid,level,transferredtoday FROM " . db_prefix("accounts") . " WHERE login='$to'";
$result = db_query($sql);
if (db_num_rows($result)==1){
$row = db_fetch_assoc($result);
$maxout = $session['user']['level']*getsetting("maxtransferout",25);
$maxtfer = $row['level']*getsetting("transferperlevel",25);
if ($session['user']['amountouttoday']+$amt > $maxout) {
output("`@Elessa`6 shakes her head, \"`@I'm sorry, but I cannot complete that transfer; you are not allowed to transfer more than `^%s`@ gold total per day.`6\"",$maxout);
}else if ($maxtfer<$amt){
output("`@Elessa`6 shakes her head, \"`@I'm sorry, but I cannot complete that transfer; `&%s`@ may only receive up to `^%s`@ gold per day.`6\"",$row['name'],$maxtfer);
}else if($row['transferredtoday']>=getsetting("transferreceive",3)){
output("`@Elessa`6 shakes her head, \"`@I'm sorry, but I cannot complete that transfer; `&%s`@ has received too many transfers today, you will have to wait until tomorrow.`6\"",$row['name']);
}else if($amt<(int)$session['user']['level']){
output("`@Elessa`6 shakes her head, \"`@I'm sorry, but I cannot complete that transfer; you might want to send a worthwhile transfer, at least as much as your level.`6\"");
}else if($row['acctid']==$session['user']['acctid']){
output("`@Elessa`6 glares at you, her eyes flashing dangerously, \"`@You may not transfer money to yourself! That makes no sense!`6\"");
}else{
debuglog("transferred $amt gold to", $row['acctid']);
$session['user']['gold']-=$amt;
if ($session['user']['gold']<0){
//withdraw in case they don't have enough on hand.
$session['user']['goldinbank']+=$session['user']['gold'];
$session['user']['gold']=0;
}
$session['user']['amountouttoday']+= $amt;
$sql = "UPDATE ". db_prefix("accounts") . " SET goldinbank=goldinbank+$amt,transferredtoday=transferredtoday+1 WHERE acctid='{$row['acctid']}'";
db_query($sql);
output("`@Elessa`6 smiles, \"`@The transfer has been completed!`6\"");
$subj = array("`^You have received a money transfer!`0");
$body = array("`&%s`6 has transferred `^%s`6 gold to your bank account!",$session['user']['name'],$amt);
systemmail($row['acctid'],$subj,$body);
}
}else{
output("`@Elessa`6 looks up from her ledger with a bit of surprise on her face, \"`@I'm terribly sorry, but I seem to have run into an accounting error, would you please try telling me what you wish to transfer again?`6\"");
}
}
}elseif($op=="deposit"){
output("`0");
rawoutput("<form action='bank.php?op=depositfinish' method='POST'>");
$balance = translate_inline("`@Elessa`6 says, \"`@You have a balance of `^%s`@ gold in the bank.`6\"`n");
$debt = translate_inline("`@Elessa`6 says, \"`@You have a `\$debt`@ of `^%s`@ gold to the bank.`6\"`n");
output_notl($session['user']['goldinbank']>=0?$balance:$debt,number_format(abs($session['user']['goldinbank']),0,$point,$sep));
output("`6Searching through all your pockets and pouches, you calculate that you currently have `^%s`6 gold on hand.`n`n", number_format($session['user']['gold'],0,$point,$sep));
$dep = translate_inline("`^Deposit how much?");
$pay = translate_inline("`^Pay off how much?");
output_notl($session['user']['goldinbank']>=0?$dep:$pay);
$dep = translate_inline("Deposit");
rawoutput(" <input id='input' name='amount' width=5 > <input type='submit' class='button' value='$dep'>");
output("`n`iEnter 0 or nothing to deposit it all`i");
rawoutput("</form>");
rawoutput("<script language='javascript'>document.getElementById('input').focus();</script>",true);
addnav("","bank.php?op=depositfinish");
}elseif($op=="depositfinish"){
$amount = abs((int)httppost('amount'));
if ($amount==0){
$amount=$session['user']['gold'];
}
$notenough = translate_inline("`\$ERROR: Not enough gold in hand to deposit.`n`n`^You plunk your `&%s`^ gold on the counter and declare that you would like to deposit all `&%s`^ gold of it.`n`n`@Elessa`6 stares blandly at you for a few seconds until you become self conscious and recount your money, realizing your mistake.");
$depositdebt = translate_inline("`@Elessa`6 records your deposit of `^%s `6gold in her ledger. \"`@Thank you, `&%s`@. You now have a debt of `\$%s`@ gold to the bank and `^%s`@ gold in hand.`6\"");
$depositbalance= translate_inline("`@Elessa`6 records your deposit of `^%s `6gold in her ledger. \"`@Thank you, `&%s`@. You now have a balance of `^%s`@ gold in the bank and `^%s`@ gold in hand.`6\"");
if ($amount>$session['user']['gold']){
output_notl($notenough,number_format($session['user']['gold'],0,$point,$sep),number_format($amount,0,$point,$sep));
}else{
debuglog("deposited " . $amount . " gold in the bank");
$session['user']['goldinbank']+=$amount;
$session['user']['gold']-=$amount;
output_notl($session['user']['goldinbank']>=0?$depositbalance:$depositdebt,number_format($amount,0,$point,$sep),$session['user']['name'], number_format(abs($session['user']['goldinbank']),0,$point,$sep),number_format($session['user']['gold'],0,$point,$sep));
}
}elseif($op=="borrow"){
$maxborrow = $session['user']['level']*getsetting("borrowperlevel",20);
$borrow = translate_inline("Borrow");
$balance = translate_inline("`@Elessa`6 scans through her ledger, \"`@You have a balance of `^%s`@ gold in the bank.`6\"`n");
$debt = translate_inline("`@Elessa`6 scans through her ledger, \"`@You have a `\$debt`@ of `^%s`@ gold to the bank.`6\"`n");
rawoutput("<form action='bank.php?op=withdrawfinish' method='POST'>");
output_notl($session['user']['goldinbank']>=0?$balance:$debt,number_format(abs($session['user']['goldinbank']),0,$point,$sep));
output("`6\"`@How much would you like to borrow `&%s`@? At your level, you may borrow up to a total of `^%s`@ from the bank.`6\"`n`n",$session['user']['name'], $maxborrow);
rawoutput(" <input id='input' name='amount' width=5 > <input type='hidden' name='borrow' value='x'><input type='submit' class='button' value='$borrow'>");
output("`n(Money will be withdrawn until you have none left, the remainder will be borrowed)");
rawoutput("</form>");
rawoutput("<script language='javascript'>document.getElementById('input').focus();</script>");
addnav("","bank.php?op=withdrawfinish");
}elseif($op=="withdraw"){
$withdraw = translate_inline("Withdraw");
$balance = translate_inline("`@Elessa`6 scans through her ledger, \"`@You have a balance of `^%s`@ gold in the bank.`6\"`n");
$debt = translate_inline("`@Elessa`6 scans through her ledger, \"`@You have a `\$debt`@ of `^%s`@ gold in the bank.`6\"`n");
rawoutput("<form action='bank.php?op=withdrawfinish' method='POST'>");
output_notl($session['user']['goldinbank']>=0?$balance:$debt,number_format(abs($session['user']['goldinbank']),0,$point,$sep));
output("`6\"`@How much would you like to withdraw `&%s`@?`6\"`n`n",$session['user']['name']);
rawoutput("<input id='input' name='amount' width=5 > <input type='submit' class='button' value='$withdraw'>");
output("`n`iEnter 0 or nothing to withdraw it all`i");
rawoutput("</form>");
rawoutput("<script language='javascript'>document.getElementById('input').focus();</script>");
addnav("","bank.php?op=withdrawfinish");
}elseif($op=="withdrawfinish"){
$amount=abs((int)httppost('amount'));
if ($amount==0){
$amount=abs($session['user']['goldinbank']);
}
if ($amount>$session['user']['goldinbank'] && httppost('borrow')=="") {
output("`\$ERROR: Not enough gold in the bank to withdraw.`^`n`n");
output("`6Having been informed that you have `^%s`6 gold in your account, you declare that you would like to withdraw all `^%s`6 of it.`n`n", number_format($session['user']['goldinbank'],0,$point,$sep), number_format($amount,0,$point,$sep));
output("`@Elessa`6 looks at you for a few moments without blinking, then advises you to take basic arithmetic. You realize your folly and think you should try again.");
}else if($amount>$session['user']['goldinbank']){
$lefttoborrow = $amount;
$didwithdraw = 0;
$maxborrow = $session['user']['level']*getsetting("borrowperlevel",20);
if ($lefttoborrow<=$session['user']['goldinbank']+$maxborrow){
if ($session['user']['goldinbank']>0){
output("`6You withdraw your remaining `^%s`6 gold.", number_format($session['user']['goldinbank'],0,$point,$sep));
$lefttoborrow-=$session['user']['goldinbank'];
$session['user']['gold']+=$session['user']['goldinbank'];
$session['user']['goldinbank']=0;
debuglog("withdrew $amount gold from the bank");
$didwithdraw = 1;
}
if ($lefttoborrow-$session['user']['goldinbank'] > $maxborrow){
if ($didwithdraw) {
output("`6Additionally, you ask to borrow `^%s`6 gold.", number_format($leftoborrow,0,$point,$sep));
} else {
output("`6You ask to borrow `^%s`6 gold.", number_format($lefttoborrow,0,$point,$sep));
}
output("`@Elessa`6 looks up your account and informs you that you may only borrow up to `^%s`6 gold.", number_format($maxborrow,0,$point,$sep));
}else{
if ($didwithdraw) {
output("`6Additionally, you borrow `^%s`6 gold.", number_format($lefttoborrow,0,$point,$sep));
} else {
output("`6You borrow `^%s`6 gold.", number_format($lefttoborrow,0,$point,$sep));
}
$session['user']['goldinbank']-=$lefttoborrow;
$session['user']['gold']+=$lefttoborrow;
debuglog("borrows $lefttoborrow gold from the bank");
output("`@Elessa`6 records your withdrawal of `^%s `6gold in her ledger. \"`@Thank you, `&%s`@. You now have a debt of `\$%s`@ gold to the bank and `^%s`@ gold in hand.`6\"", number_format($amount,0,$point,$sep),$session['user']['name'], number_format(abs($session['user']['goldinbank']),0,$point,$sep),number_format($session['user']['gold'],0,$point,$sep));
}
}else{
output("`6Considering the `^%s`6 gold in your account, you ask to borrow `^%s`6. `@Elessa`6 peers through her ledger, runs a few calculations and then informs you that, at your level, you may only borrow up to a total of `^%s`6 gold.", number_format($session['user']['goldinbank'],0,$point,$sep), number_format($lefttoborrow-$session['user']['goldinbank'],0,$point,$sep), number_format($maxborrow,0,$point,$sep));
}
}else{
$session['user']['goldinbank']-=$amount;
$session['user']['gold']+=$amount;
debuglog("withdrew $amount gold from the bank");
output("`@Elessa`6 records your withdrawal of `^%s `6gold in her ledger. \"`@Thank you, `&%s`@. You now have a balance of `^%s`@ gold in the bank and `^%s`@ gold in hand.`6\"", number_format($amount,0,$point,$sep),$session['user']['name'], number_format(abs($session['user']['goldinbank']),0,$point,$sep),number_format($session['user']['gold'],0,$point,$sep));
}
}
villagenav();
addnav("Money");
if ($session['user']['goldinbank']>=0){
addnav("W?Withdraw","bank.php?op=withdraw");
addnav("D?Deposit","bank.php?op=deposit");
if (getsetting("borrowperlevel",20)) addnav("L?Take out a Loan","bank.php?op=borrow");
}else{
addnav("D?Pay off Debt","bank.php?op=deposit");
if (getsetting("borrowperlevel",20)) addnav("L?Borrow More","bank.php?op=borrow");
}
if (getsetting("allowgoldtransfer",1)){
if ($session['user']['level']>=getsetting("mintransferlev",3) || $session['user']['dragonkills']>0){
addnav("M?Transfer Money","bank.php?op=transfer");
}
}
page_footer();
?>