<#
data division.
linkage section.
01 require.
01 response.
01 title.
procedure division.
move "Customers" to title.
perform set-cache.
#>
<h1>Customers</h1>

<div class='btn-group actions'>
<a class='btn btn-primary' href='/customer/new'>New Customer</a>
</div>

<#
local mysql.

perform require using "mysql" giving mysql.

local options.
local connection.

perform showpage.

showpage section.
move object to options.
move "root" to user in options.
move "" to password in options.
move "cobolscriptwebsite" to database in options.

perform createConnection in mysql using options giving connection.
perform connect in connection.
perform query in connection using "select Id, Name from customers order by Id" showcustomers.

showcustomers section using err, rows, fields.
if err then 
    display "<h2>" err "</h2>"
    perform end in connection
    stop run
end-if.
#>
<table class="table-striped table-bordered list">
<tr><th>Name</th></tr>
<#
local k.
local n.
move length in rows to n.
move 0 to k.
local row.

perform varying k from 1 to n
    move rows(k) to row
#>
<tr>
<td><a href="/customer/view?id=${Id in row}">${Name in row}</a></td>
</tr>
<#
end-perform
#>
</table>
<#
.
perform end in connection.
stop run.

set-cache section.
* Date in the past
local headers.
move object to headers.
move "Mon, 20 Feb 1998 07:00:00 GMT" to headers("Expires").
local today.
perform new in Date giving today.
perform toString in today giving today.
* Always modified
move today to headers("Last-modified").
* HTTP/1.1
move "no-cache, must-revalidate" to headers("Cache-control").
* HTTP/1.0
move "no-cache" to headers("Pragma").
perform writeHead in response using 200 headers.
#>

