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