Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -------------------------------
- -- ------- Variables ------- --
- -------------------------------
- local screenX, screenY = term.getSize()
- local admin = { username = 'admin', password = 'pass' } -- admin details to view bookings
- local logged = false
- local name, time, reason = '', '', ''
- local menu = 'Reception Desk'
- local bookingsFile = 'bookings.txt'
- local bookings = {}
- os.pullEvent = os.pullEventRaw
- -- Background
- local bg = {[1]={[1]=2048,[2]=2048,[3]=2048,[4]=2048,[5]=2048,[6]=2048,[7]=2048,[8]=2048,[9]=2048,[10]=2048,[11]=2048,[12]=2048,[13]=2048,[14]=2048,[15]=2048,[16]=2048,[17]=2048,[18]=2048,[19]=2048,[20]=2048,[21]=2048,[22]=2048,[23]=2048,[24]=2048,[25]=2048,[26]=2048,[27]=2048,[28]=2048,[29]=2048,[30]=2048,[31]=2048,[32]=2048,[33]=2048,[34]=2048,[35]=2048,[36]=2048,[37]=2048,[38]=2048,[39]=2048,[40]=2048,[41]=2048,[42]=2048,[43]=2048,[44]=2048,[45]=2048,[46]=2048,[47]=2048,[48]=2048,[49]=2048,[50]=2048,[51]=2048,},[2]={[1]=2048,[2]=2048,[3]=2048,[4]=2048,[5]=2048,[6]=2048,[7]=2048,[8]=2048,[9]=2048,[10]=2048,[11]=2048,[12]=2048,[13]=2048,[14]=2048,[15]=2048,[16]=2048,[17]=2048,[18]=2048,[19]=2048,[20]=2048,[21]=2048,[22]=2048,[23]=2048,[24]=2048,[25]=2048,[26]=2048,[27]=2048,[28]=2048,[29]=2048,[30]=2048,[31]=2048,[32]=2048,[33]=2048,[34]=2048,[35]=2048,[36]=2048,[37]=2048,[38]=2048,[39]=2048,[40]=2048,[41]=2048,[42]=2048,[43]=2048,[44]=2048,[45]=2048,[46]=2048,[47]=2048,[48]=2048,[49]=2048,[50]=2048,[51]=2048,},[3]={[1]=2048,[2]=2048,[3]=2048,[4]=2048,[5]=2048,[6]=2048,[7]=2048,[8]=2048,[9]=2048,[10]=2048,[11]=2048,[12]=2048,[13]=2048,[14]=2048,[15]=2048,[16]=2048,[17]=2048,[18]=2048,[19]=2048,[20]=2048,[21]=2048,[22]=2048,[23]=2048,[24]=2048,[25]=2048,[26]=2048,[27]=2048,[28]=2048,[29]=2048,[30]=2048,[31]=2048,[32]=2048,[33]=2048,[34]=2048,[35]=2048,[36]=2048,[37]=2048,[38]=2048,[39]=2048,[40]=2048,[41]=2048,[42]=2048,[43]=2048,[44]=2048,[45]=2048,[46]=2048,[47]=2048,[48]=2048,[49]=2048,[50]=2048,[51]=2048,},[4]={[1]=512,[2]=512,[3]=512,[4]=512,[5]=512,[6]=512,[7]=512,[8]=512,[9]=512,[10]=512,[11]=512,[12]=512,[13]=512,[14]=512,[15]=512,[16]=512,[17]=512,[18]=512,[19]=512,[20]=512,[21]=512,[22]=512,[23]=512,[24]=512,[25]=512,[26]=512,[27]=512,[28]=512,[29]=512,[30]=512,[31]=512,[32]=512,[33]=512,[34]=512,[35]=512,[36]=512,[37]=512,[38]=512,[39]=512,[40]=512,[41]=512,[42]=512,[43]=512,[44]=512,[45]=512,[46]=512,[47]=512,[48]=512,[49]=512,[50]=512,[51]=512,},[5]={[1]=512,[2]=512,[3]=512,[4]=512,[5]=512,[6]=512,[7]=512,[8]=512,[9]=512,[10]=512,[11]=512,[12]=512,[13]=512,[14]=512,[15]=512,[16]=512,[17]=512,[18]=512,[19]=512,[20]=512,[21]=512,[22]=512,[23]=512,[24]=512,[25]=512,[26]=512,[27]=512,[28]=512,[29]=512,[30]=512,[31]=512,[32]=512,[33]=512,[34]=512,[35]=512,[36]=512,[37]=512,[38]=512,[39]=512,[40]=512,[41]=512,[42]=512,[43]=512,[44]=512,[45]=512,[46]=512,[47]=512,[48]=512,[49]=512,[50]=512,[51]=512,},[6]={[1]=512,[2]=512,[3]=512,[4]=512,[5]=512,[6]=512,[7]=512,[8]=512,[9]=512,[10]=512,[11]=512,[12]=512,[13]=512,[14]=512,[15]=512,[16]=512,[17]=512,[18]=512,[19]=512,[20]=512,[21]=512,[22]=512,[23]=512,[24]=512,[25]=512,[26]=512,[27]=512,[28]=512,[29]=512,[30]=512,[31]=512,[32]=512,[33]=512,[34]=512,[35]=512,[36]=512,[37]=512,[38]=512,[39]=512,[40]=512,[41]=512,[42]=512,[43]=512,[44]=512,[45]=512,[46]=512,[47]=512,[48]=512,[49]=512,[50]=512,[51]=512,},[7]={[1]=512,[2]=512,[3]=512,[4]=512,[5]=512,[6]=512,[7]=512,[8]=512,[9]=512,[10]=512,[11]=512,[12]=512,[13]=512,[14]=512,[15]=512,[16]=512,[17]=512,[18]=512,[19]=512,[20]=512,[21]=512,[22]=512,[23]=512,[24]=512,[25]=512,[26]=512,[27]=512,[28]=512,[29]=512,[30]=512,[31]=512,[32]=512,[33]=512,[34]=512,[35]=512,[36]=512,[37]=512,[38]=512,[39]=512,[40]=512,[41]=512,[42]=512,[43]=512,[44]=512,[45]=512,[46]=512,[47]=512,[48]=512,[49]=512,[50]=512,[51]=512,},[8]={[1]=512,[2]=512,[3]=512,[4]=512,[5]=512,[6]=512,[7]=512,[8]=512,[9]=512,[10]=512,[11]=512,[12]=512,[13]=512,[14]=512,[15]=512,[16]=512,[17]=512,[18]=512,[19]=512,[20]=512,[21]=512,[22]=512,[23]=512,[24]=512,[25]=512,[26]=512,[27]=512,[28]=512,[29]=512,[30]=512,[31]=512,[32]=512,[33]=512,[34]=512,[35]=512,[36]=512,[37]=512,[38]=512,[39]=512,[40]=512,[41]=512,[42]=512,[43]=512,[44]=512,[45]=512,[46]=512,[47]=512,[48]=512,[49]=512,[50]=512,[51]=512,},[9]={[1]=512,[2]=512,[3]=512,[4]=512,[5]=512,[6]=512,[7]=512,[8]=512,[9]=512,[10]=512,[11]=512,[12]=512,[13]=512,[14]=512,[15]=512,[16]=512,[17]=512,[18]=512,[19]=512,[20]=512,[21]=512,[22]=512,[23]=512,[24]=512,[25]=512,[26]=512,[27]=512,[28]=512,[29]=512,[30]=512,[31]=512,[32]=512,[33]=512,[34]=512,[35]=512,[36]=512,[37]=512,[38]=512,[39]=512,[40]=512,[41]=512,[42]=512,[43]=512,[44]=512,[45]=512,[46]=512,[47]=512,[48]=512,[49]=512,[50]=512,[51]=512,},[10]={[1]=512,[2]=512,[3]=512,[4]=512,[5]=512,[6]=512,[7]=512,[8]=512,[9]=512,[10]=512,[11]=512,[12]=512,[13]=512,[14]=512,[15]=512,[16]=512,[17]=512,[18]=512,[19]=512,[20]=512,[21]=512,[22]=512,[23]=512,[24]=512,[25]=512,[26]=512,[27]=512,[28]=512,[29]=512,[30]=512,[31]=512,[32]=512,[33]=512,[34]=512,[35]=512,[36]=512,[37]=512,[38]=512,[39]=512,[40]=512,[41]=512,[42]=512,[43]=512,[44]=512,[45]=512,[46]=512,[47]=512,[48]=512,[49]=512,[50]=512,[51]=512,},[11]={[1]=512,[2]=512,[3]=512,[4]=512,[5]=512,[6]=512,[7]=512,[8]=512,[9]=512,[10]=512,[11]=512,[12]=512,[13]=512,[14]=512,[15]=512,[16]=512,[17]=512,[18]=512,[19]=512,[20]=512,[21]=512,[22]=512,[23]=512,[24]=512,[25]=512,[26]=512,[27]=512,[28]=512,[29]=512,[30]=512,[31]=512,[32]=512,[33]=512,[34]=512,[35]=512,[36]=512,[37]=512,[38]=512,[39]=512,[40]=512,[41]=512,[42]=512,[43]=512,[44]=512,[45]=512,[46]=512,[47]=512,[48]=512,[49]=512,[50]=512,[51]=512,},[12]={[1]=512,[2]=512,[3]=512,[4]=512,[5]=512,[6]=512,[7]=512,[8]=512,[9]=512,[10]=512,[11]=512,[12]=512,[13]=512,[14]=512,[15]=512,[16]=512,[17]=512,[18]=512,[19]=512,[20]=512,[21]=512,[22]=512,[23]=512,[24]=512,[25]=512,[26]=512,[27]=512,[28]=512,[29]=512,[30]=512,[31]=512,[32]=512,[33]=512,[34]=512,[35]=512,[36]=512,[37]=512,[38]=512,[39]=512,[40]=512,[41]=512,[42]=512,[43]=512,[44]=512,[45]=512,[46]=512,[47]=512,[48]=512,[49]=512,[50]=512,[51]=512,},[13]={[1]=512,[2]=512,[3]=512,[4]=512,[5]=512,[6]=512,[7]=512,[8]=512,[9]=512,[10]=512,[11]=512,[12]=512,[13]=512,[14]=512,[15]=512,[16]=512,[17]=512,[18]=512,[19]=512,[20]=512,[21]=512,[22]=512,[23]=512,[24]=512,[25]=512,[26]=512,[27]=512,[28]=512,[29]=512,[30]=512,[31]=512,[32]=512,[33]=512,[34]=512,[35]=512,[36]=512,[37]=512,[38]=512,[39]=512,[40]=512,[41]=512,[42]=512,[43]=512,[44]=512,[45]=512,[46]=512,[47]=512,[48]=512,[49]=512,[50]=512,[51]=512,},[14]={[1]=512,[2]=512,[3]=512,[4]=512,[5]=512,[6]=512,[7]=512,[8]=512,[9]=512,[10]=512,[11]=512,[12]=512,[13]=512,[14]=512,[15]=512,[16]=512,[17]=512,[18]=512,[19]=512,[20]=512,[21]=512,[22]=512,[23]=512,[24]=512,[25]=512,[26]=512,[27]=512,[28]=512,[29]=512,[30]=512,[31]=512,[32]=512,[33]=512,[34]=512,[35]=512,[36]=512,[37]=512,[38]=512,[39]=512,[40]=512,[41]=512,[42]=512,[43]=512,[44]=512,[45]=512,[46]=512,[47]=512,[48]=512,[49]=512,[50]=512,[51]=512,},[15]={[1]=512,[2]=512,[3]=512,[4]=512,[5]=512,[6]=512,[7]=512,[8]=512,[9]=512,[10]=512,[11]=512,[12]=512,[13]=512,[14]=512,[15]=512,[16]=512,[17]=512,[18]=512,[19]=512,[20]=512,[21]=512,[22]=512,[23]=512,[24]=512,[25]=512,[26]=512,[27]=512,[28]=512,[29]=512,[30]=512,[31]=512,[32]=512,[33]=512,[34]=512,[35]=512,[36]=512,[37]=512,[38]=512,[39]=512,[40]=512,[41]=512,[42]=512,[43]=512,[44]=512,[45]=512,[46]=512,[47]=512,[48]=512,[49]=512,[50]=512,[51]=512,},[16]={[1]=512,[2]=512,[3]=512,[4]=512,[5]=512,[6]=512,[7]=512,[8]=512,[9]=512,[10]=512,[11]=512,[12]=512,[13]=512,[14]=512,[15]=512,[16]=512,[17]=512,[18]=512,[19]=512,[20]=512,[21]=512,[22]=512,[23]=512,[24]=512,[25]=512,[26]=512,[27]=512,[28]=512,[29]=512,[30]=512,[31]=512,[32]=512,[33]=512,[34]=512,[35]=512,[36]=512,[37]=512,[38]=512,[39]=512,[40]=512,[41]=512,[42]=512,[43]=512,[44]=512,[45]=512,[46]=512,[47]=512,[48]=512,[49]=512,[50]=512,[51]=512,},[17]={[1]=512,[2]=512,[3]=512,[4]=512,[5]=512,[6]=512,[7]=512,[8]=512,[9]=512,[10]=512,[11]=512,[12]=512,[13]=512,[14]=512,[15]=512,[16]=512,[17]=512,[18]=512,[19]=512,[20]=512,[21]=512,[22]=512,[23]=512,[24]=512,[25]=512,[26]=512,[27]=512,[28]=512,[29]=512,[30]=512,[31]=512,[32]=512,[33]=512,[34]=512,[35]=512,[36]=512,[37]=512,[38]=512,[39]=512,[40]=512,[41]=512,[42]=512,[43]=512,[44]=512,[45]=512,[46]=512,[47]=512,[48]=512,[49]=512,[50]=512,[51]=512,},[18]={[1]=512,[2]=512,[3]=512,[4]=512,[5]=512,[6]=512,[7]=512,[8]=512,[9]=512,[10]=512,[11]=512,[12]=512,[13]=512,[14]=512,[15]=512,[16]=512,[17]=512,[18]=512,[19]=512,[20]=512,[21]=512,[22]=512,[23]=512,[24]=512,[25]=512,[26]=512,[27]=512,[28]=512,[29]=512,[30]=512,[31]=512,[32]=512,[33]=512,[34]=512,[35]=512,[36]=512,[37]=512,[38]=512,[39]=512,[40]=512,[41]=512,[42]=512,[43]=512,[44]=512,[45]=512,[46]=512,[47]=512,[48]=512,[49]=512,[50]=512,[51]=512,},[19]={[1]=256,[2]=256,[3]=256,[4]=256,[5]=256,[6]=256,[7]=256,[8]=256,[9]=256,[10]=256,[11]=256,[12]=256,[13]=256,[14]=256,[15]=256,[16]=256,[17]=256,[18]=256,[19]=256,[20]=256,[21]=256,[22]=256,[23]=256,[24]=256,[25]=256,[26]=256,[27]=256,[28]=256,[29]=256,[30]=256,[31]=256,[32]=256,[33]=256,[34]=256,[35]=256,[36]=256,[37]=256,[38]=256,[39]=256,[40]=256,[41]=256,[42]=256,[43]=256,[44]=256,[45]=256,[46]=256,[47]=256,[48]=256,[49]=256,[50]=256,[51]=256,},}
- -------------------------------
- -- ------- Functions ------- --
- -------------------------------
- local function getCenter( l, x1, x2 )
- return math.floor( ( ( x2 + x1 ) - ( type(l) == 'string' and #l or l ) ) / 2 ) + 1
- end
- local function centerWrite( text, yPos, txtCol, bgCol )
- term.setCursorPos( ( screenX - #text ) / 2, yPos )
- write( text )
- end
- local function sWrite( text, xPos, yPos, txtCol, bgCol )
- term.setCursorPos( xPos, yPos )
- write( text )
- end
- local function format( text, l, last )
- return text:len() > l and text:sub( 1, l - last:len() ) .. last or text
- end
- local function block( text, x, y, txtCol, bgCol )
- for i = y, y + 2 do
- sWrite( string.rep( ' ', text:len() + 2 ), x, i, nil, bgCol )
- end
- sWrite( text, getCenter( text, x, x + text:len() + 1 ), y + 1, txtCol, bgCol )
- end
- local function checkArea( cx, cy, mx, my, ax, ay )
- return cx >= mx and cx < mx + ax and cy >= my and cy <= my + ay
- end
- local function limitRead( properties, ... )
- local buttons = { ... }
- properties = properties or {}
- properties.visibleLength = properties.visibleLength or nil
- properties.nLimit = properties.nLimit or nil
- properties.replaceChar = properties.replaceChar and ( properties.replaceChar:sub( 1, 1 ) == '' and nil or properties.replaceChar:sub( 1, 1 ) ) or nil
- properties.temp = properties.temp or ''
- properties.txtCol = properties.txtCol or colours.white
- properties.bgCol = properties.bgCol or colours.blue
- properties.oldBgCol = properties.oldBgCol or colours.lightBlue
- local rString = properties.temp
- term.setCursorBlink( true )
- sWrite( rString .. string.rep( ' ', properties.visibleLength - rString:len() ), properties.x, properties.y, properties.txtCol, properties.bgCol )
- term.setCursorPos( properties.x + ( #rString > properties.visibleLength and properties.visibleLength or #rString ), properties.y )
- while true do
- local event, p1, x, y = os.pullEvent()
- if event == "char" then
- -- Character event
- if #rString < properties.nLimit then
- rString = rString .. p1
- if #rString - 1 < properties.visibleLength then
- write( properties.replaceChar or p1 )
- elseif not properties.replaceChar then
- term.setCursorPos( properties.x, properties.y )
- write( rString:sub( #rString - properties.visibleLength + 1 ) )
- end
- end
- elseif event == "key" then
- if p1 == keys.backspace and #rString > 0 then
- -- Backspace
- rString = rString:sub( 1, #rString - 1 )
- local xPos, yPos = term.getCursorPos()
- term.setCursorPos(xPos-1, yPos)
- write(" ")
- term.setCursorPos(xPos-1, yPos)
- if #rString + 1 > properties.visibleLength then
- term.setCursorPos( properties.x, properties.y )
- write( properties.replaceChar and string.rep( properties.replaceChar, properties.visibleLength ) or rString:sub( #rString - properties.visibleLength + 1 ) )
- end
- elseif p1 == keys.enter and rString:len() > 0 then
- sWrite( format( rString, properties.visibleLength, ' ...' ) .. string.rep( ' ', rString:len() < properties.visibleLength and properties.visibleLength - rString:len() or 0 ), properties.x, properties.y, properties.txtCol, properties.oldBgCol )
- term.setCursorBlink( false )
- return rString
- end
- elseif event == 'mouse_click' and p1 == 1 then
- for i = 1, #buttons do
- local but = buttons[i]
- if checkArea( x, y, but.x, but.y, but.l - 1, but.h - 1 ) then
- term.setCursorBlink( false )
- sWrite( format( rString, properties.visibleLength, ' ...' ) .. string.rep( ' ', rString:len() < properties.visibleLength and properties.visibleLength - rString:len() or 0 ), properties.x, properties.y, properties.txtCol, properties.oldBgCol )
- if but.a then but.a() return nil end
- if but.kill then return nil
- elseif rString:len() > 0 then return rString end
- end
- end
- end
- end
- end
- local function splitToTable( s )
- return
- s:len() < screenX - 7 and { s }
- or ( s:len() >= screenX - 7 and s:len() < ( screenX - 8 ) * 2 ) and { s:sub( 1, screenX - 8 ), s:sub( screenX - 7, ( screenX - 8 ) * 2 - 1 ) }
- or { s:sub( 1, screenX - 8 ), s:sub( screenX - 7, ( screenX - 8 ) * 2 - 1 ), s:sub( ( screenX - 8 ) * 2 ) }
- end
- local function saveBooking( name, time, reason )
- if not fs.exists( bookingsFile ) then local f = fs.open( bookingsFile, 'w' ) f.close() end
- local file = fs.open( bookingsFile, 'a' )
- if file then
- file.writeLine( name )
- file.writeLine( time )
- file.writeLine( textutils.serialize( splitToTable( reason ) ) )
- file.close()
- return 'Your booking has been recorded.', true
- else
- return 'An error has occured!', false
- end
- end
- local function getBookings()
- local file = fs.open( bookingsFile, 'r' )
- if file then
- local a = {}
- local i = 1
- local n, t, r
- for line in file.readLine do
- if i == 1 then
- n = line
- elseif i == 2 then
- t = line
- elseif i == 3 then
- r = line
- table.insert( a, { name = n, time = t, reason = textutils.unserialize( r ) } )
- i = 0
- end
- i = i + 1
- end
- file.close()
- return a
- else
- return {}
- end
- end
- local function info( msg, success )
- -- Clear other buttons
- block( ' ', getCenter( 5, 1, 26 ), 15, nil, colours.cyan )
- block( ' ', getCenter( 5, 26, screenX ), 15, nil, colours.cyan )
- block( msg, getCenter( msg, 1, screenX ), 15, colours.white, success and colours.lime or colours.red )
- end
- local function init( title )
- centerWrite( title, 2, colours.white, colours.blue )
- if title == 'Reception Desk' then
- -- Text
- sWrite( 'Book an apointment', 8, 4, colours.lime, colours.cyan )
- sWrite( 'Name:', 4, 6, colours.blue, colours.cyan )
- sWrite( ' so we know who you are', 4, 7, colours.lightGrey, colours.cyan )
- sWrite( 'Time:', 4, 9, colours.blue, colours.cyan )
- sWrite( ' what time do you want to meet', 4, 10, colours.lightGrey, colours.cyan )
- sWrite( 'Reason:', 4, 12, colours.blue, colours.cyan )
- sWrite( ' why do you want to meet', 4, 13, colours.lightGrey, colours.cyan )
- sWrite( 'view bookings', screenX - 12, screenY, colours.grey, colours.lightGrey )
- -- Text area
- for y = 6, 12, 3 do
- sWrite( string.rep( ' ', 33 ), 12, y, nil, colours.lightBlue )
- end
- -- Buttons
- block( 'Apply', getCenter( 5, 1, 26 ), 15, colours.white, colours.lime )
- block( 'Clear', getCenter( 5, 26, screenX ), 15, colours.black, colours.red )
- else
- if logged then
- bookings = getBookings()
- if type( bookings ) == 'table' then
- if #bookings > 0 then
- sWrite( 'There are ' .. #bookings .. ' bookings', 8, 5, colours.lime, colours.cyan )
- else
- block( ' No bookings ', getCenter( 22, 1, screenX ), 7, colours.black, colours.red )
- end
- elseif bookings == 'error' then
- block( 'Error opening file!', getCenter( 22, 1, screenX ), 7, colours.black, colours.red )
- bookings = {}
- end
- else
- -- Text
- sWrite( 'Please login', 8, 4, colours.lime, colours.cyan )
- sWrite( 'Username:', 4, 6, colours.blue, colours.cyan )
- sWrite( 'Password:', 4, 8, colours.blue, colours.cyan )
- -- Text area
- for y = 6, 8, 2 do
- sWrite( string.rep( ' ', 33 ), 14, y, nil, colours.lightBlue )
- end
- -- Buttons
- block( 'Login', getCenter( 5, 1, screenX ), 15, colours.white, colours.lime )
- --block( 'Cancel', getCenter( 6, 26, screenX ), 15, colours.black, colours.red )
- end
- -- Text
- sWrite( 'back', screenX - 3, screenY, colours.grey, colours.lightGrey )
- end
- -- Reset variables
- name, time, reason = '', '', ''
- end
- -------------------------------
- -- ------- Main loop ------- --
- -------------------------------
- while true do
- init( menu )
- while true do
- if menu == 'Reception Desk' then
- -- Get user's name
- name = limitRead( { visibleLength = 33, nLimit = 50, x = 12, y = 6 },
- { x = getCenter( 5, 1, 26 ), y = 15, h = 3, l = 7, kill = false }, { x = getCenter( 5, 26, screenX ), y = 15, h = 3, l = 7, kill = true }, { x = 39, y = screenY, h = 1, l = 12, kill = false, a = function() menu = 'Current bookings' end } )
- if not name then break end
- -- Get time
- time = limitRead( { visibleLength = 33, nLimit = 50, x = 12, y = 9 },
- { x = getCenter( 5, 1, 26 ), y = 15, h = 3, l = 7, kill = false }, { x = getCenter( 5, 26, screenX ), y = 15, h = 3, l = 7, kill = true }, { x = 39, y = screenY, h = 1, l = 12, kill = false, a = function() menu = 'Current bookings' end } )
- if not time then break end
- -- Get reason
- reason = limitRead( { visibleLength = 33, nLimit = 132, x = 12, y = 12 },
- { x = getCenter( 5, 1, 26 ), y = 15, h = 3, l = 7, kill = false }, { x = getCenter( 5, 26, screenX ), y = 15, h = 3, l = 7, kill = true }, { x = 39, y = screenY, h = 1, l = 12, kill = false, a = function() menu = 'Current bookings' end } )
- if not reason then break end
- info( saveBooking( name, time, reason ) )
- sleep( 2 )
- break
- else
- if logged then
- if #bookings > 0 then
- for y = 7, 17 do
- end
- sWrite( 'Booking # /' .. #bookings, 5, 8, colours.lightBlue, colours.black )
- sWrite( 'Name:', 5, 10, colours.white, colours.black )
- sWrite( 'Time:', 5, 11, colours.white, colours.black )
- sWrite( 'Reason:', 5, 13, colours.white, colours.black )
- end
- local sel = 1
- while true do
- if #bookings > 0 then
- sWrite( sel, 14, 8, colours.yellow, colours.black )
- sWrite( format( bookings[sel].name, 33, ' ..' ) .. string.rep( ' ', 36 - bookings[sel].name:len() ), 11, 10, colours.red, colours.black )
- sWrite( format( bookings[sel].time, 33, ' ..' ) .. string.rep( ' ', 36 - bookings[sel].time:len() ), 11, 11, colours.red, colours.black )
- for y = 14, 16 do sWrite( string.rep( ' ', 45 ), 5, y, nil, colours.black ) end
- for i = 1, #bookings[sel].reason do
- sWrite( bookings[sel].reason[i], 5, 13 + i, colours.red, colours.black )
- end
- end
- local e, b, x, y = os.pullEvent()
- if e == 'mouse_click' and b == 1 then
- if x >= 47 and x <= screenX and y == screenY then
- -- Back
- menu = 'Reception Desk'
- logged = false
- break
- end
- elseif e == 'mouse_scroll' and #bookings > 0 then
- if b == -1 and sel > 1 then
- -- Up
- sel = sel - 1
- elseif b == 1 and sel < #bookings then
- -- Down
- sel = sel + 1
- end
- end
- end
- break
- else
- local username, password = '', ''
- -- Get username
- while username == '' do username = limitRead( { visibleLength = 33, nLimit = 50, x = 14, y = 6 },
- { x = getCenter( 5, 1, 26 ), y = 15, h = 3, l = 7, kill = false }, { x = getCenter( 5, 26, screenX ), y = 15, h = 3, l = 7, kill = true }, { x = 47, y = screenY, h = 1, l = 4, kill = false, a = function() menu = 'Reception Desk' end } ) end
- if not username then break end
- -- Get password
- while password == '' do password = limitRead( { visibleLength = 33, nLimit = 50, x = 14, y = 8 },
- { x = getCenter( 5, 1, 26 ), y = 15, h = 3, l = 7, kill = false }, { x = getCenter( 5, 26, screenX ), y = 15, h = 3, l = 7, kill = true }, { x = 47, y = screenY, h = 1, l = 4, kill = false, a = function() menu = 'Reception Desk' end } ) end
- if not password then break end
- if username == admin.username and password == admin.password then
- info( 'Logged in!', true )
- logged = true
- else
- info( 'Incorrect credentials!', false )
- end
- sleep( 2 )
- break
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement