Hi,
Let's create a simple app for city folks so kids can watch E.T Movie at summer parties. They just need to enter their name and the system will register them and give them a code to access and watch the movie. Easy peasy.
We'll create a file called ticket.html
We'll set up the ticket request process and call it proc_ticket.prg
We'll set up the ticket request process and call it proc_ticket.prg
It's super basic code that handles everything in a simple way - it even creates the table! Obviously this could be improved a ton: indexes, maximum requests, number of tickets, capacity limits... but I'll leave that for you all to work on :D
We will start the HIX server, and run localhost/ticket.html and voil脿, our app is ready to go


All the data will be in our table

Is it easy? :D
Let's create a simple app for city folks so kids can watch E.T Movie at summer parties. They just need to enter their name and the system will register them and give them a code to access and watch the movie. Easy peasy.
We'll create a file called ticket.html
We'll set up the ticket request process and call it proc_ticket.prg
<!DOCTYPE html>
<html>
<body>
<h2>Movie Ticket</h2>
<form action="proc_ticket.prg" method='post' >
<label for="user_name">Name:</label><br>
<input type="text" name="user_name" value="John"><br><br>
<input type="submit" value="Give me a ticket">
</form>
<p>If you click the "Submit" button, the form-data will be sent to a page called "proc_ticket.prg".</p>
</body>
</html>#define FILE_TICKET hb_dirbase() + 'ticket.dbf'
#define MAX_TIMEOUT 5
function main()
local lExist := file( FILE_TICKET )
local hData := UPost()
local cAlias, aDbf, cMessage
if ! file( FILE_TICKET )
aDbf := {}
AAdd(aDbf, { 'name', 'C', 40, 0 })
AAdd(aDbf, { 'data', 'D', 8, 0 })
AAdd(aDbf, { 'key' , 'C', 5, 0 })
dbCreate( FILE_TICKET, aDbf )
endif
USE ( FILE_TICKET ) SHARED NEW
cAlias := alias()
(cAlias)->( Dbappend() )
if (cAlias)->( TRlock() )
(cAlias)->name := hData[ 'user_name' ]
(cAlias)->data := date()
(cAlias)->key := key()
(cAlias)->( DbUnlock() )
endif
(cAlias)->( DbCommit() )
cMessage := '<html>'
cMessage += '<h1>Request processed !</h1><hr>'
cMessage += '<h3>Hi ' + hData[ 'user_name' ] + '. Your access code is ' + (cAlias)->key + '</h3>'
cMessage += '<hr><small>' + 'This ticket was processed at ' + dtoc( date() ) + ' ' + time() + '</small>'
cMessage += '</html>'
(cAlias)->( DbCloseArea() )
RETU cMessage
//---------------------------------------------------//
function TRLock()
LOCAL lRlock := .F.
LOCAL nIni := Seconds()
LOCAL cAlias := Alias()
LOCAL nElapsed
WHILE !lRlock
lRlock := (cAlias)->(DbRlock())
if !lRlock
nElapsed := Seconds() - nIni
if nElapsed >= MAX_TIMEOUT
EXIT // Timeout
endif
hb_IdleSleep(0.01)
endif
END
RETU lRlock
//---------------------------------------------------//
FUNCTION Key()
LOCAL cKey := ''
LOCAL cWords := 'abcdefghijklmnopqrstuvwxyz'
LOCAL nI, nPos
FOR nI := 1 TO 5
nPos := hb_RandomInt(1, Len(cWords))
cKey += SubStr(cWords, nPos, 1)
NEXT
RETURN cKeyWe will start the HIX server, and run localhost/ticket.html and voil脿, our app is ready to go


All the data will be in our table

Is it easy? :D
Salutacions, saludos, regards
"...programar es f谩cil, hacer programas es dif铆cil..."
UT Page -> https://carles9000.github.io/
Forum UT -> https://discord.gg/bq8a9yGMWh
HIX -> https://github.com/carles9000/hix
"...programar es f谩cil, hacer programas es dif铆cil..."
UT Page -> https://carles9000.github.io/
Forum UT -> https://discord.gg/bq8a9yGMWh
HIX -> https://github.com/carles9000/hix