Advertisement
lego11

Nebraska Pay Chiosco

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