FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index mod_harbour HIX -> Ticket Project (I)
Posts: 1283
Joined: Fri Feb 10, 2006 02:34 PM
HIX -> Ticket Project (I)
Posted: Sun Oct 26, 2025 11:11 AM
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
Code (html): Select all Collapse
<!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>
We'll set up the ticket request process and call it proc_ticket.prg
Code (php): Select all Collapse
#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 cKey
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
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
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: HIX -&gt; Ticket Project (I)
Posted: Sun Oct 26, 2025 11:13 AM
Working url please ;-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1283
Joined: Fri Feb 10, 2006 02:34 PM
Re: HIX -&gt; Ticket Project (I)
Posted: Sun Oct 26, 2025 11:20 AM
Antonio,

This is an exercise for you to create on your computer... If we finish the whole exercise (a few chapters) maybe I'll put it on some URL. :wink:

C.
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
Posts: 1445
Joined: Mon Oct 10, 2005 02:38 PM
Re: HIX -&gt; Ticket Project (I)
Posted: Sun Oct 26, 2025 07:14 PM

Bona tarda Charly,

A ver, yo estoy muy lejos de esto.

Me qued茅 en FWeb, lo recuerdas? Que por cierto no aparece en el historial evolutivo, y ah铆 empez贸 todo.. creo.

Pero cada vez que te leo me da un subid贸n.

Pregunto (ya te he dicho que estoy muy lejos):

-Si las funciones TRlock() y Key() las quiero tener para m谩s menesteres, las puedo poner en un PRG independiente? C贸mo se llamar铆a a este PRG para poder ejecutar estas funciones?

Ya nos dices,

Un Saludo

Carlos G.



FiveWin 25.12 + Harbour 3.2.0dev (r2502110321), BCC 7.7 Windows 11 Home

Posts: 1283
Joined: Fri Feb 10, 2006 02:34 PM
Re: HIX -&gt; Ticket Project (I)
Posted: Mon Oct 27, 2025 06:12 AM
Bones,
FiveWiDi wrote: Me qued茅 en FWeb, lo recuerdas? Que por cierto no aparece en el historial evolutivo, y ah铆 empez贸 todo.. creo.
Cierto, pero eso fue en php. Todav铆a hoy en dia en la administraci贸n hay una aplicaci贸n que lo usa y va como un cohete. :D
FiveWiDi wrote: Si las funciones TRlock() y Key() las quiero tener para m谩s menesteres, las puedo poner en un PRG independiente? C贸mo se llamar铆a a este PRG para poder ejecutar estas funciones?,
En una aplicaci贸n cl谩sica esto seria tener una librer铆a que enlazar铆as a tu aplicaci贸n y todo estaria en una saco llamado exe. En la web vas cargando a medida que necesites. Ahora misma tienes la opci贸n de meter en este caso estas 2 funciones en un fichero llamado por ejemplo milib.prg y en tu c贸digo hacer un #include 'mylib.prg'

Esta previsto poder cargar en el momento de arrancar el servidor ficheros hrb que serian como librerias.

Prueba el ejercicio propuesto y vamos avanzando... Vais a ver que es mas simple de lo que imaginais

C.
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

Continue the discussion