View difference between Paste ID: TFQY7tRH and 1HLa4c8c
SHOW: | | - or go back to the newest paste.
1
local maxw, maxh = term.getSize()
2
3
--IMPLEMENTAZIONE DEL DRAWFILLEDBOX
4
local function drawPixelInternal(xPos, yPos)
5
    term.setCursorPos(xPos, yPos)
6
    term.write(" ")
7
end
8
9
local tColourLookup = {}
10
for n = 1,16 do
11
    tColourLookup[string.byte("0123456789abcdef", n, n)] = 2^(n-1)
12
end
13
14
function drawFilledBox(startX, startY, endX, endY, nColour)
15
    if type(startX) ~= "number" or type(startX) ~= "number" or
16
       type(endX) ~= "number" or type(endY) ~= "number" or
17
       (nColour ~= nil and type(nColour) ~= "number") then
18
        error("Expected startX, startY, endX, endY, colour", 2)
19
    end
20
21
    startX = math.floor(startX)
22
    startY = math.floor(startY)
23
    endX = math.floor(endX)
24
    endY = math.floor(endY)
25
26
    if nColour then
27
        term.setBackgroundColor(nColour)
28
    end
29
    if startX == endX and startY == endY then
30
        drawPixelInternal(startX, startY)
31
        return
32
    end
33
34
    local minX = math.min(startX, endX)
35
    if minX == startX then
36
        minY = startY
37
        maxX = endX
38
        maxY = endY
39
    else
40
        minY = endY
41
        maxX = startX
42
        maxY = startY
43
    end
44
45
    for x = minX, maxX do
46
        for y = minY, maxY do
47
            drawPixelInternal(x, y)
48
        end
49
    end
50
end
51
52
function clear()
53
    sfondo(colors.lightBlue)
54
    term.clear()
55
    term.setCursorPos(1, 1)
56
end
57
 
58
function colore(sfumatura)
59
    term.setTextColour(sfumatura)
60
end
61
62
function sfondo(sfumaturaSfondo)
63
    term.setBackgroundColour(sfumaturaSfondo)
64
end
65
66
function titolo(testo)
67
    drawFilledBox(1, 1, maxw, 1, colors.yellow)
68
    term.setCursorPos((maxw - #testo) / 2, 1)
69
    colore(colors.black)
70
    term.write(testo)
71
    sfondo(colors.lightBlue)
72
end
73
74
function update()
75-
    term.setCursorPos(1, 21)
75+
    shell.run("/desktop")
76-
    shell.run("rm startup")
76+
77-
    shell.run("pastebin get y1AP0iNY startup") -- Inserire paste di nPay
77+
78-
    os.reboot()
78+
79
    clear()
80
    text = "ARRIVEDERCI!"
81
    colore(colors.white)
82
    term.setCursorPos((maxw - #text) / 2, math.floor(maxh / 2))
83
    term.write(text)
84
    colore(colors.black)
85
    text2 = "Tra poco saråA5A0 possibile eseguire"
86
    text3 = "una nuova operazione..."
87
    term.setCursorPos((maxw - #text2) / 2, math.floor(maxh / 2) + 2)
88
    print(text2)
89
    term.setCursorPos((maxw - #text3) / 2, math.floor(maxh / 2) + 3)
90
    print(text3)
91
    os.sleep(0.5)
92
    update()
93
end
94
95
function drawCard()
96
    drawFilledBox(6, 7, 24, 7, colors.blue)
97
    drawFilledBox(6, 15, 24, 15, colors.blue)
98
    drawFilledBox(5, 8, 25, 14, colors.blue)
99
100
    drawFilledBox(7, 9, 23, 9, colors.lightGray)
101
    drawFilledBox(7, 12, 23, 13, colors.black)
102
end
103
104
mag = peripheral.wrap("bottom")
105
bl = "BN Credit"
106
107
sfondo(colors.lightBlue)
108
clear()
109
110
colore(colors.white)
111
print(" ")
112
print("                      ___            ")
113
print("              _ __   / _ \\__ _ _   _ ")
114
print("             | '_ \\ / /_)/ _  | | | |")
115
print("             | | | / ___/ (_| | |_| |")
116
print("             |_| |_\\/    \\__,_|\\__, |")
117
print("                                |___/ ")
118
119
-- Bottoni login/registrati
120
121
drawFilledBox(14, 10, 38, 12, colors.white)
122
term.setCursorPos(23, 11)
123
colore(colors.black)
124
term.write("Accedi")
125
126
drawFilledBox(14, 15, 38, 17, colors.white)
127
term.setCursorPos(21, 16)
128
colore(colors.black)
129
term.write("Sei nuovo?")
130
131
while true do
132
    event, key, x, y = os.pullEvent("mouse_click")
133
    if event == "mouse_click" and x >= 14 and x <= 38 and y >= 15 and y <= 17 then
134
        -- Registrazione nuovo utente
135
        clear()
136
        titolo("Registrati a nPay")
137
        term.setCursorPos(1, 3)
138
        print("Inserisci un nome utente e una password sicura.")
139
        term.setCursorPos(1, 5)
140
        colore(colors.gray)
141
        print("Premi ENTER per confermare i dati inseriti.\nSe i dati sono corretti, il campo diventeråA5A0 verde.\nSe sono errati, il programma chiederåA5A0 di reinserirli nuovamente.")
142
143
        -- Nome Utente
144
        term.setCursorPos(1, 10)
145
        colore(colors.black)
146
        term.write("Nome utente:")
147
        term.setCursorPos(14, 10)
148
        colore(colors.white)
149
        utenteAccettato = false
150
        conteggioErrori = 0
151
        while utenteAccettato == false do
152
            utente = read()
153
            checkuser = http.get("http://172.16.20.220/luanet/servlets/nebraskapay.php?auth=no&richiesta=verifica&utente=" .. utente).readAll()
154
            tabcheckuser = textutils.unserialize(checkuser)
155
            if tabcheckuser.stato == "NO" then
156
                term.setCursorPos(14, 10)
157
                colore(colors.lime)
158
                term.write(utente)
159
                colore(colors.white)
160
                utenteAccettato = true
161
            else
162
                term.setCursorPos(14, 10)
163
                colore(colors.red)
164
                term.write("Utente giåA5A0 esistente!")
165
                sleep(2)
166
                term.setCursorPos(14, 10)
167
                colore(colors.white)
168
                term.write("                       ")
169
                term.setCursorPos(14, 10)
170
                conteggioErrori = conteggioErrori + 1
171
                if conteggioErrori > 2 then
172
                    term.setCursorPos(14, 10)
173
                    colore(colors.red)
174
                    term.write("Tre tentativi di immissione errati.")
175
                    sleep(2)
176
                    term.setCursorPos(14, 10)
177
                    colore(colors.white)
178
                    term.write("                       ")
179
                    term.setCursorPos(14, 10)
180
                    clear()
181
                    os.reboot()
182
                end
183
            end
184
        end
185
186
        --password
187
        colore(colors.black)
188
        term.setCursorPos(1, 12)
189
        term.write("Password:")
190
        term.setCursorPos(11, 12)
191
        colore(colors.white)
192
193
        passAccettata = false
194
        conteggioErrori = 0
195
        while passAccettata == false do
196
            password1 = read("#")
197
            colore(colors.black)
198
            term.setCursorPos(1, 13)
199
            term.write("Verifica:")
200
            term.setCursorPos(11, 13)
201
            colore(colors.white)
202
            local password2 = read("#")
203
            if password1 == password2 then
204
                term.setCursorPos(11, 12)
205
                colore(colors.lime)
206
                term.write("###############")
207
                term.setCursorPos(11, 13)
208
                term.write("###############")
209
                colore(colors.white)
210
                passAccettata = true
211
            else
212
                colore(colors.red)
213
                term.setCursorPos(11, 12)
214
                term.write("Le password non corrispondono!    ")
215
                term.setCursorPos(1, 13)
216
                colore(colors.white)
217
                term.write("                               ")
218
                sleep(1.5)
219
                term.setCursorPos(11, 12)
220
                term.write("                               ")
221
                term.setCursorPos(11, 12)
222
                conteggioErrori = conteggioErrori + 1
223
                if conteggioErrori > 2 then
224
                    term.setCursorPos(14, 12)
225
                    colore(colors.red)
226
                    term.write("Tre tentativi di immissione errati.")
227
                    sleep(1.5)
228
                    term.setCursorPos(14, 12)
229
                    colore(colors.white)
230
                    term.write("                       ")
231
                    term.setCursorPos(14, 12)
232
                    clear()
233
                    os.reboot()
234
                end
235
            end
236
        end
237
238
        --crea l'account
239
240
        term.setCursorPos(1, 17)
241
        creaAccount = http.get("http://172.16.20.220/luanet/servlets/nebraskapay.php?auth=" .. password1 .. "&utente=" .. utente .. "&richiesta=crea&valore=0").readAll()
242
        tabCreaAccount = textutils.unserialize(creaAccount)
243
        if tabCreaAccount.stato == "OA" then
244
            colore(colors.lime)
245
            print("Conto creato con successo.")
246
            sleep(1.5)
247
            clear()
248
            os.reboot()
249
        else
250
            colore(colors.red)
251
            print("Errore durante la creazione del conto.")
252
            sleep(1.5)
253
            clear()
254
            os.reboot()
255
        end
256
257
    elseif event == "mouse_click" and x >= 14 and x <= 38 and y >= 10 and y <= 12 then
258
        clear()
259
        titolo("Accedi a nPay")
260
        term.setCursorPos(1, 3)
261
        colore(colors.black)
262
        print("Inserire i propri dati.")
263
        colore(colors.gray)
264
        print("\nPremere Enter per confermare i dati inseriti.\nSe i dati sono corretti, il campo diventeråA5A0 verde.\nSe sono errati, il programma chiederåA5A0 di reinserirli nuovamente.")
265
266
        --nomeutente
267
        term.setCursorPos(1, 10)
268
        colore(colors.black)
269
        term.write("Nome utente:")
270
        term.setCursorPos(15, 10)
271
        colore(colors.white)
272
        utenteAccettato = false
273
        conteggioErrori = 0
274
        while utenteAccettato == false do
275
            utente = read()
276
            checkuser = http.get("http://172.16.20.220/luanet/servlets/nebraskapay.php?auth=no&richiesta=verifica&utente=" .. utente).readAll()
277
            tabcheckuser = textutils.unserialize(checkuser)
278
            if tabcheckuser.stato == "OK" then
279
                term.setCursorPos(15, 10)
280
                colore(colors.lime)
281
                term.write(utente)
282
                colore(colors.white)
283
                utenteAccettato = true
284
            else
285
                term.setCursorPos(15, 10)
286
                colore(colors.red)
287
                term.write("Utente errato!          ")
288
                sleep(2)
289
                term.setCursorPos(15, 10)
290
                colore(colors.white)
291
                term.write("                       ")
292
                term.setCursorPos(15, 10)
293
                conteggioErrori = conteggioErrori + 1
294
                if conteggioErrori > 2 then
295
                    term.setCursorPos(15, 10)
296
                    colore(colors.red)
297
                    term.write("Tre tentativi di immissione errati.")
298
                    sleep(2)
299
                    term.setCursorPos(15, 10)
300
                    colore(colors.white)
301
                    term.write("                       ")
302
                    term.setCursorPos(15, 10)
303
                    clear()
304
                    os.reboot()
305
                end
306
            end
307
        end
308
309
        --password
310
        colore(colors.black)
311
        term.setCursorPos(1,12)
312
        term.write("Password:")
313
        term.setCursorPos(15, 12)
314
         
315
        conteggioErrori = 0
316
        passAccettata = false
317
        while passAccettata == false do
318
            colore(colors.white)
319
            password = read("#")
320
            colore(colors.black)
321
            checkuser = http.get("http://172.16.20.220/luanet/servlets/nebraskapay.php?auth=" .. password .. "&richiesta=addebito&valore=0&utente=".. utente).readAll()
322
            risposta = textutils.unserialize(checkuser)
323
            if risposta.stato == "OK" then
324
                term.setCursorPos(15, 12)
325
                colore(colors.lime)
326
                term.write("##############               ")
327
                colore(colors.white)
328
                passAccettata = true
329
                else
330
                    term.setCursorPos(15, 12)
331
                    colore(colors.red)
332
                    term.write("Password errata!            ")
333
                    conteggioErrori = conteggioErrori + 1
334
                    sleep(2)
335
                    term.setCursorPos(15, 12)
336
                    term.write("                               ")
337
                    term.setCursorPos(15, 12)
338
                if conteggioErrori > 2 then
339
                    term.setCursorPos(15, 12)
340
                    colore(colors.red)
341
                    term.write("Tre tentativi di immissione errati.")
342
                    sleep(2)
343
                    term.setCursorPos(15, 12)
344
                    term.write("                               ")
345
                    term.setCursorPos(15, 12)
346
                    clear()
347
                    os.reboot()
348
                end
349
            end
350
        end
351
352
        conteggioErrori = 0
353
        -- Pagina in cui scegli le operazioni da fare
354
355
        while true do
356
            --Ricontrolla il saldo per gestire l'aggiornamento di piåA5B9 operazioni
357
            checkuser = http.get("http://172.16.20.220/luanet/servlets/nebraskapay.php?auth="..password.."&richiesta=addebito&valore=0&utente="..utente).readAll()
358
            risposta = textutils.unserialize(checkuser)
359
            saldo = tonumber(risposta.saldo)
360
            --Disegna la finestra del pannello utente
361
            clear()
362
            titolo("Pannello utente nPay")
363
            term.setCursorPos(1, 3)
364
            term.write("Benvenuto, ")
365
            colore(colors.white)
366
            term.write(utente)
367
            colore(colors.black)
368
            term.write("!         Saldo: ")
369
            colore(colors.white)
370
            term.write(saldo)
371
            colore(colors.black)
372
            term.write(" IC")
373
            print("\n\nOperazioni disponibili:\n")
374
            sfondo(colors.white)
375
            print(" Carica denaro su nPay  \n")
376
            print(" Preleva denaro da nPay \n")
377
            print(" Trasferisci denaro     \n")
378
            print(" Estratto conto         \n")
379
            colore(colors.red)
380
            print(" Disconnettiti da nPay  \n")
381
            colore(colors.black)
382
383
            antitonto = os.startTimer(60)
384
385
            event, key, x, y = os.pullEventRaw()
386
            if event == "mouse_click" and y == 7 and x <= 24 then       --Pulsante carica denaro su nPay
387
                clear()
388
                titolo("Caricamento denaro su nPay")
389
390
                drawCard()
391
392
                sfondo(colors.lightBlue)
393
                colore(colors.black)
394
                term.setCursorPos(30, 8)
395
                print("INSERIRE LA CARTA")
396
                term.setCursorPos(29, 10)
397
                print("NEL LETTORE IN BASSO")
398
                drawFilledBox(34, 14, 42, 14, colors.white)
399
                term.setCursorPos(35, 14)
400
                term.write("Annulla")
401
402
                mag.setInsertCardLight(true)
403
                finalBreakC = false
404
                while true do
405
                    event, arg1, arg2, arg3 = os.pullEventRaw()
406
                    if event == "mouse_click" and arg3 == 14 and arg2 >= 34 and arg2 <= 42 then -- arg2 = x | arg3 = y
407
                        mag.setInsertCardLight(false)
408
                        clear()
409
                        term.setCursorPos(1,1)
410
                        break
411
                    elseif event == "mag_swipe" then
412
                        mag.setInsertCardLight(false)
413
                        tabel = textutils.unserialize(arg1)
414
                        if tabel == "" or tabel == nil then
415
                            clear()
416
                            titolo("Caricamento denaro da nPay")
417
418
                            drawCard()
419
420
                            sfondo(colors.lightBlue)
421
                            term.setCursorPos(36, 10)
422
                            colore(colors.red)
423
                            term.write("ERRORE!")
424
                            term.setCursorPos(30, 12)
425
                            colore(colors.black)
426
                            term.write("Carta smagnetizzata!")
427
                            os.sleep(3)
428
                            break
429
                        elseif tabel.t ~= "cc" or tabel.e ~= "BN" then
430
                            clear()
431
                            titolo("Caricamento denaro da nPay")
432
433
                            drawCard()
434
435
                            sfondo(colors.lightBlue)
436
                            term.setCursorPos(36, 10)
437
                            colore(colors.red)
438
                            term.write("ERRORE!")
439
                            term.setCursorPos(31, 12)
440
                            colore(colors.black)
441
                            term.write("Carta non valida!")
442
                            os.sleep(3)
443
                            break
444
                        else
445
                            while true do
446
                                clear()
447
                                titolo("Caricamento denaro su nPay")
448
                                colore(colors.gray)
449
                                print("\n\nDisponibilitåA5A0 su carta:  " .. tabel.v .. " IC")
450
                                colore(colors.red)
451
                                term.setCursorPos(1, 14)
452
                                term.write("ATTENZIONE:")
453
                                colore(colors.black)
454
                                term.setCursorPos(1, 15)
455
                                term.write("Eccezionalmente, grazie ai 600 voti di marzo,")
456
								--term.write("Per le operazioni inferiori a 50 000 IC,")
457
                                term.setCursorPos(1, 16)
458
								print("le operazioni saranno GRATUITE fino al 4 aprile!")
459
                                --print("si applica una commissione del 0.15%.")
460
                                --print("Oltre 50 000 IC la commissione åA5A8 del 0.05%.")
461
                                term.setCursorPos(1, 5)
462
                                term.write("Importo da caricare: ")
463
                                colore(colors.white)
464
                                credito = tonumber(tabel.v)
465
                                credit = read()
466
                                if tonumber(credit) == "" or tonumber(credit) == nil or tonumber(credit) <= 0 then
467
                                    colore(colors.red)
468
                                    term.setCursorPos(22, 5)
469
                                    term.write("Importo errato!                    ")
470
                                    colore(colors.black)
471
                                    sleep(1.5)
472
                                    clear()
473
                                else
474
                                    if tonumber(credit) >= 50000 then
475
										--commissioni = tonumber(credit) * 0.005
476
										commissioni = tonumber(credit) * 0
477
                                    else
478
                                       --commissioni = tonumber(credit) * 0.015
479
									   commissioni = tonumber(credit) * 0
480
                                    end
481
									crediton = credit + commissioni
482
                                    if tonumber(tabel.v) >= crediton then
483
                                        tab = http.get("http://172.16.20.220/luanet/servlets/nebraskapay.php?utente=" .. utente .. "&auth=" .. password .. "&richiesta=accredito&valore=" .. credit).readAll()
484
                                        tabella = textutils.unserialize(tab)
485
                                        tabr = {}
486
                                        tabr.t = tabel.t
487
                                        tabr.e = tabel.e
488
                                        tabr.p = tabel.p
489
                                        tabr.v = tonumber(tabel.v) - crediton
490
                                        ncr = textutils.serialize(tabr)
491
                                        clear()
492
                                        titolo("Caricamento denaro su nPay")
493
494
                                        drawCard()
495
496
                                        colore(colors.black)
497
                                        sfondo(colors.lightBlue)
498
                                        term.setCursorPos(29, 10)
499
                                        print("RE-INSERIRE LA CARTA")
500
                                        term.setCursorPos(29, 12)
501
                                        print("NEL LETTORE IN BASSO")
502
503
                                        mag.setInsertCardLight(true)
504
                                        mag.beginWrite(ncr, bl)
505
                                        za2, carta = os.pullEvent("mag_write_done")
506
                                        mag.setInsertCardLight(false)
507
                                        clear()
508
                                        titolo("Caricamento denaro su nPay")
509
510
                                        colore(colors.lime)
511
                                        term.setCursorPos(1, 3)
512
                                        print("Operazione completata!")
513
                                        colore(colors.black)
514
                                        term.setCursorPos(1, 5)
515
                                        print("Denaro accreditato: " .. credit .. " IC")
516
                                        print("Commissioni:        " .. commissioni .. " IC")
517
                                        term.setCursorPos(1, 8)
518
                                        print("Saldo sul conto:    " .. tabella.credito .. " IC")
519
                                        print("Saldo sulla carta:  " .. tabr.v .. " IC")
520
                                        sfondo(colors.white)
521
                                        term.setCursorPos(1, 12)
522
                                        term.write(" Torna alla pagina principale ")
523
                                        sfondo(colors.lightBlue)
524
525
                                        antiTonto2 = os.startTimer(15)
526
                                        while true do
527
                                            local event, arg1, arg2, arg3 = os.pullEventRaw()
528
                                            if event == "mouse_click" and arg3 == 12 and arg2 <= 30 or event == "timer" and arg1 == antiTonto2 then -- arg2 = x | arg3 = y
529
                                                finalBreakC = true
530
                                                break
531
                                            end
532
                                        end
533
                                        break
534
                                    else
535
                                        colore(colors.red)
536
                                        term.setCursorPos(22, 5)
537
                                        term.write("Credito su carta insufficente.")
538
                                        colore(colors.black)
539
                                        sleep(1.5)
540
                                        clear()
541
                                    end
542
                                end
543
                            end
544
                            if finalBreakC then
545
                                break
546
                            end
547
                        end
548
                    end
549
                end
550
551
            elseif event == "mouse_click" and y == 9 and x <= 24 then  --Pulsante preleva denaro da nPay
552
                clear()
553
                titolo("Prelievo denaro da nPay")
554
555
                drawCard()
556
557
                sfondo(colors.lightBlue)
558
                colore(colors.black)
559
                term.setCursorPos(30, 8)
560
                print("INSERIRE LA CARTA")
561
                term.setCursorPos(29, 10)
562
                print("NEL LETTORE IN BASSO")
563
                drawFilledBox(34, 14, 42, 14, colors.white)
564
                term.setCursorPos(35, 14)
565
                term.write("Annulla")
566
567
                mag.setInsertCardLight(true)
568
                finalBreakP = false
569
                while true do
570
                    event, arg1, arg2, arg3 = os.pullEventRaw()
571
                    if event == "mouse_click" and arg3 == 14 and arg2 >= 34 and arg2 <= 42 then -- arg2 = x | arg3 = y
572
                        mag.setInsertCardLight(false)
573
                        clear()
574
                        term.setCursorPos(1,1)
575
                        break
576
                    elseif event == "mag_swipe" then
577
                        mag.setInsertCardLight(false)
578
                        sfondo(colors.lightBlue)
579
                        clear()
580
                        tabel = textutils.unserialize(arg1)
581
                        if tabel == "" or tabel == nil then
582
                            clear()
583
                            titolo("Prelievo denaro da nPay")
584
585
                            drawCard()
586
587
                            sfondo(colors.lightBlue)
588
                            term.setCursorPos(36, 10)
589
                            colore(colors.red)
590
                            term.write("ERRORE!")
591
                            term.setCursorPos(30, 12)
592
                            colore(colors.black)
593
                            term.write("Carta smagnetizzata!")
594
                            os.sleep(3)
595
                            break
596
                        elseif tabel.t ~= "cc" or tabel.e ~= "BN" then
597
                            clear()
598
                            titolo("Prelievo denaro da nPay")
599
600
                            drawCard()
601
602
                            sfondo(colors.lightBlue)
603
                            term.setCursorPos(36, 10)
604
                            colore(colors.red)
605
                            term.write("ERRORE!")
606
                            term.setCursorPos(31, 12)
607
                            colore(colors.black)
608
                            term.write("Carta non valida!")
609
                            os.sleep(3)
610
                            break
611
                        else
612
                            while true do
613
                                tabr = {}
614
                                tabr.e = tabel.e
615
                                tabr.p = tabel.p
616
                                tabr.t = tabel.t
617
                                tab1 = http.get("http://172.16.20.220/luanet/servlets/nebraskapay.php?utente=" .. utente .. "&auth=" .. password .. "&richiesta=accredito&valore=0").readAll()
618
                                tab3 = textutils.unserialize(tab1)
619
                                clear()
620
                                titolo("Prelievo denaro da nPay")
621
                                colore(colors.gray)
622
                                print("\n\nDisponibilitåA5A0 su conto:  " .. saldo .. " IC")
623
                                colore(colors.black)
624
                                term.setCursorPos(1, 5)
625
                                term.write("Importo da ritirare: ")
626
                                colore(colors.white)
627
                                credito = tonumber(tabel.v)
628
                                credit = read()
629
                                if tonumber(credit) == "" or tonumber(credit) == nil or tonumber(credit) <= 0 then
630
                                    colore(colors.red)
631
                                    term.setCursorPos(22, 5)
632
                                    term.write("Importo errato!                    ")
633
                                    colore(colors.black)
634
                                    sleep(1.5)
635
                                    clear()
636
                                else
637
                                    tab = http.get("http://172.16.20.220/luanet/servlets/nebraskapay.php?utente=" .. utente .. "&auth=" .. password .. "&richiesta=addebito&valore=" .. credit).readAll()
638
                                    tabella = textutils.unserialize(tab)
639
                                    if tabella.stato == "DI" then
640
                                        colore(colors.red)
641
                                        term.setCursorPos(22, 5)
642
                                        term.write("Credito su carta insufficente.")
643
                                        colore(colors.black)
644
                                        sleep(1.5)
645
                                        clear()
646
                                    else
647
                                        tabr.v = tonumber(tabel.v) + tonumber(credit)
648
                                        ncr = textutils.serialize(tabr)
649
                                        mag.setInsertCardLight(true)
650
                                        mag.beginWrite(ncr, bl)
651
                                        clear()
652
                                        titolo("Prelievo denaro da nPay")
653
654
                                        drawCard()
655
656
                                        colore(colors.black)
657
                                        sfondo(colors.lightBlue)
658
                                        term.setCursorPos(29, 10)
659
                                        print("RE-INSERIRE LA CARTA")
660
                                        term.setCursorPos(29, 12)
661
                                        print("NEL LETTORE IN BASSO")
662
663
                                        mag.setInsertCardLight(true)
664
                                        event = os.pullEvent("mag_write_done")
665
                                        mag.setInsertCardLight(false)
666
                                        clear()
667
                                        titolo("Prelievo denaro da nPay")
668
669
                                        colore(colors.lime)
670
                                        term.setCursorPos(1, 3)
671
                                        print("Operazione completata!")
672
                                        colore(colors.black)
673
                                        term.setCursorPos(1, 5)
674
                                        print("Denaro prelevato:  " .. credit .. " IC")
675
                                        term.setCursorPos(1, 7)
676
                                        print("Saldo sul conto:   " .. tabella.credito .. " IC")
677
                                        print("Saldo sulla carta: " .. tabr.v .. " IC")
678
                                        sfondo(colors.white)
679
                                        term.setCursorPos(1, 11)
680
                                        term.write(" Torna alla pagina principale ")
681
                                        sfondo(colors.lightBlue)
682
683
                                        antiTonto2 = os.startTimer(15)
684
                                        while true do
685
                                            local event, arg1, arg2, arg3 = os.pullEventRaw()
686
                                            if event == "mouse_click" and arg3 == 11 and arg2 <= 30 or event == "timer" and arg1 == antiTonto2 then -- arg2 = x | arg3 = y
687
                                                finalBreakP = true
688
                                                break
689
                                            end
690
                                        end
691
                                        break
692
                                    end
693
                                end
694
                            end
695
                            if finalBreakP then
696
                                break
697
                            end
698
                        end
699
                    end
700
                end
701
702
            elseif event == "mouse_click" and y == 11 and x <= 24 then --Pulsante trasferisci denaro
703
                --Trasferisci denaro
704
                --inizio pagina
705
                clear()
706
                titolo("Trasferimento di denaro")
707
                term.setCursorPos(1, 3)
708
                term.write("Inserire il nome utente del beneficiario.")
709
                colore(colors.gray)
710
                print("\n\nPremere Enter per confermare i dati inseriti.\nSe i dati sono corretti, il campo diventeråA5A0 verde.\nSe sono errati, il programma chiederåA5A0 di reinserirli nuovamente.")
711
712
                --Mostra saldo
713
                term.setCursorPos(1, 10)
714
                colore(colors.gray)
715
                print("Saldo disponibile: " .. saldo .. " IC")
716
                colore(colors.black)
717
718
                --Verifica Beneficiario
719
                term.setCursorPos(1, 12)
720
                term.write("Beneficiario:")
721
                term.setCursorPos(15, 12)
722
                colore(colors.white)
723
                destAccettato = false
724
                conteggioErrori = 0
725
                while destAccettato == false do
726
                    beneficiario = read()
727
                    checkuser = http.get("http://172.16.20.220/luanet/servlets/nebraskapay.php?auth=no&richiesta=verifica&utente=" .. beneficiario).readAll()
728
                    tabcheckuser = textutils.unserialize(checkuser)
729
                    if tabcheckuser.stato == "OK" and beneficiario ~= utente then
730
                        term.setCursorPos(15, 12)
731
                        colore(colors.lime)
732
                        term.write(beneficiario)
733
                        colore(colors.white)
734
                        destAccettato = true
735
                    else
736
                        conteggioErrori = conteggioErrori + 1
737
                        term.setCursorPos(15, 12)
738
                        colore(colors.red)
739
                        if beneficiario == utente then
740
                            term.write("Non puoi inserire te stesso.")
741
                        else
742
                            term.write("Utente inesistente!         ")
743
                        end
744
                        sleep(2)
745
                        term.setCursorPos(15, 12)
746
                        colore(colors.white)
747
                        term.write("                                      ")
748
                        term.setCursorPos(15, 12)
749
                        if conteggioErrori > 2 then
750
                            term.setCursorPos(15, 12)
751
                            colore(colors.red)
752
                            term.write("Tre tentativi di immissione errati.")
753
                            sleep(2)
754
                            term.setCursorPos(15, 12)
755
                            colore(colors.white)
756
                            term.write("                                   ")
757
                            term.setCursorPos(15, 12)
758
                            clear()
759
                            os.reboot()
760
                        end
761
                    end
762
                end
763
764
                colore(colors.black)
765
                --Verifica valore dell'invio
766
                term.setCursorPos(1, 14)
767
                term.write("Importo:")
768
                term.setCursorPos(15, 14)
769
                colore(colors.white)
770
                importoAccettato = false
771
                conteggioErrori = 0
772
                while importoAccettato == false do
773
                    importo = tonumber(read())
774
                    if importo == "" or importo == nil or importo <= 0 then
775
                        conteggioErrori = conteggioErrori + 1
776
                        term.setCursorPos(15, 14)
777
                        colore(colors.red)
778
                        term.write("Importo errato!                    ")
779
                        sleep(2)
780
                        term.setCursorPos(15, 14)
781
                        colore(colors.white)
782
                        term.write("                                   ")
783
                        term.setCursorPos(15, 14)
784
                    elseif importo <= saldo and importo > 0 then
785
                        term.setCursorPos(15, 14)
786
                        colore(colors.lime)
787
                        term.write(importo .. " IC")
788
                        colore(colors.white)
789
                        importoAccettato = true
790
                    else
791
                        conteggioErrori = conteggioErrori + 1
792
                        term.setCursorPos(15, 14)
793
                        colore(colors.red)
794
                        term.write("Credito insufficiente!          ")
795
                        sleep(2)
796
                        term.setCursorPos(15, 14)
797
                        colore(colors.white)
798
                        term.write("                                   ")
799
                        term.setCursorPos(15, 14)
800
                        if conteggioErrori > 2 then
801
                            term.setCursorPos(15, 14)
802
                            colore(colors.red)
803
                            term.write("Tre tentativi di immissione errati.")
804
                            sleep(2)
805
                            term.setCursorPos(15, 14)
806
                            colore(colors.white)
807
                            term.write("                                   ")
808
                            term.setCursorPos(15, 14)
809
                            clear()
810
                            os.reboot()
811
                        end
812
                    end
813
                end
814
815
                sleep(0.5)
816
                clear()
817
                titolo("Riepilogo del trasferimento")
818
819
                text = "Vuoi inviare " .. importo .. " IC a " .. beneficiario .. "?"
820
                term.setCursorPos((maxw - #text) / 2, 6)
821
                term.write("Vuoi inviare ")
822
                colore(colors.white)
823
                term.write(tostring(importo) .. " IC ")
824
                colore(colors.black)
825
                term.write("a ")
826
                colore(colors.white)
827
                term.write(beneficiario)
828
                colore(colors.black)
829
                term.write("?")
830
831
                drawFilledBox(7, 11, 23, 13, colors.white)
832
                drawFilledBox(29, 11, 45, 13, colors.white)
833
834
                term.setCursorPos(8, 12)
835
                colore(colors.lime)
836
                term.write("Invia il denaro")
837
838
                term.setCursorPos(34, 12)
839
                colore(colors.red)
840
                term.write("Annulla")
841
842
                inviare = false
843
                while true do
844
                    event, key, x, y = os.pullEvent()
845
                    if event == "mouse_click" and x >= 7 and x <= 23 and y >= 11 and y <= 13 then
846
                        inviaDenaro = http.get("http://172.16.20.220/luanet/servlets/nebraskapay.php?auth=" .. password .. "&utente=" .. utente .. "&richiesta=trasferimento&valore=" .. importo .. "&beneficiario=" .. beneficiario).readAll()
847
                        risultatoInvio = textutils.unserialize(inviaDenaro)
848
                        if risultatoInvio.stato == "OK" then
849
                            text = "Invio del denaro riuscito."
850
                            text2 = "Nuovo saldo: " .. risultatoInvio.credito .. " IC"
851
                            sfondo(colors.lightBlue)
852
                            colore(colors.lime)
853
                            term.setCursorPos((maxw - #text) / 2, 16)
854
                            term.write(text)
855
                            colore(colors.black)
856
                            term.setCursorPos((maxw - #text2) / 2, 18)
857
                            term.write(text2)
858
                            sleep(2)
859
                            clear()
860
                            break
861
                        else
862
                            text = "Errore durante l'invio del denaro."
863
                            text2 = risultatoInvio.errore
864
                            sfondo(colors.lightBlue)
865
                            colore(colors.red)
866
                            term.setCursorPos((maxw - #text) / 2, 16)
867
                            term.write(text)
868
                            colore(colors.black)
869
                            term.setCursorPos((maxw - #text2) / 2, 18)
870
                            term.write(text2)
871
                            sleep(2)
872
                            clear()
873
                            break
874
                        end
875
                    elseif event == "mouse_click" and x >= 29 and x <= 45 and y >= 11 and y <= 13 then
876
                        sfondo(colors.lightBlue)
877
                        colore(colors.red)
878
                        text = "Operazione annullata."
879
                        term.setCursorPos((maxw - #text) / 2, 16)
880
                        term.write(text)
881
                        sleep(1.5)
882
                        clear()
883
                        break
884
                    end
885
                end
886
887
            elseif event == "mouse_click" and y == 13 and x <= 24 then --Pulsante estratto conto
888
                --Estratto Conto (inizio pagina)
889
                clear()
890
                titolo("Estratto conto")
891
892
                estratto = http.get("http://172.16.20.220/luanet/servlets/nebraskapay.php?auth=" .. password .. "&utente=" .. utente .. "&richiesta=estratto").readAll()
893
                ec = textutils.unserialize(estratto)
894
                term.setCursorPos(1, 3)
895
                print("Entrate:")
896
                colore(colors.lime)
897
                print(ec.entrata1)
898
                print(ec.entrata2)
899
                print(ec.entrata3)
900
                print(ec.entrata4)
901
                colore(colors.black)
902
                print("\nUscite:")
903
                colore(colors.red)
904
                print(ec.uscita1)
905
                print(ec.uscita2)
906
                print(ec.uscita3)
907
                print(ec.uscita4)
908
                term.setCursorPos(1, 18)
909
                sfondo(colors.white)
910
                colore(colors.black)
911
                term.write(" Torna al menåA5B9 principale ")
912
                while true do
913
                    event, key, x, y = os.pullEventRaw()
914
                    if event == "mouse_click" and x <= 26 and y == 18 then
915
                        break
916
                    end
917
                end
918
919
            elseif event == "mouse_click" and y == 15 and x <= 24 then --Pulsante disconnetti da nPay
920
                disconnetti()
921
922
            elseif event == "timer" and key == antitonto then --Butta fuori l'utente se non fa niente
923
                disconnetti()
924
925
            elseif event == "mouse_click" and x == maxw and y == maxh then -- Auto aggiornamento su magic corner (pannello utente)
926
                update()
927
            end
928
        end
929
930
    elseif event == "mouse_click" and x == maxw and y == maxh then -- Auto aggiornamento su magic corner (schermata principale)
931
      update()
932
    end
933
end