timekeeper

[Abandoned unfinished] CGI web application in C for time tracking. (My first, just a learning project)
Log | Files | Refs | README

commit 66c34ea9297fbc2cb16500dc6571b25e6d677b65
parent e8d56cfbc1decf0069c884a2535ed15ba59b19dd
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date:   Tue, 19 Mar 2024 19:46:42 -0700

Allow showing specific time periods in /main

Diffstat:
Mpages/main.c | 25++++++++++++++++++++-----
1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/pages/main.c b/pages/main.c @@ -357,6 +357,10 @@ pagemain(struct pagedata *pd) enum kcgi_err status; enum time_field tf; struct timesheet *times, *end; + unsigned int period; + int current; + char heading[64]; + int h1len; if (!pd->user) return errorpage(pd, KHTTP_401); @@ -378,21 +382,32 @@ pagemain(struct pagedata *pd) if (status != KCGI_OK) return status; - if (gettimes(pd, pd->user->hash, 0, &times)) + period = pd->req.fieldmap[KeyPeriod] ? + pd->req.fieldmap[KeyPeriod]->parsed.i : 0; + current = period == 0; + if (gettimes(pd, pd->user->hash, period, &times)) err(1, "gettimes"); - else if (!times && !(times = newtimesheet())) + if (current && !times && !(times = newtimesheet())) err(1, "gettimes"); for (end = times; end->next; end = end->next) ; - if (end->set & EndTimeFlag && !inserttimesheet(newtimesheet(), end)) { + if (current && end->set & EndTimeFlag && + !inserttimesheet(newtimesheet(), end)) { freetimesheet(times); return KCGI_SYSTEM; } - if ((status = htmlwithin(pd, KELEM_H1, "Timekeeper")) != KCGI_OK || + if (current) + h1len = strlcpy(heading, "Timekeeper", sizeof(heading)); + else + h1len = snprintf(heading, sizeof(heading), "Timekeeper, Period %d", period); + if (h1len < 0 || (unsigned int)h1len >= sizeof(heading)) + return KCGI_SYSTEM; + + if ((status = htmlwithin(pd, KELEM_H1, heading)) != KCGI_OK || (status = exportform(pd)) != KCGI_OK || - (status = breakform(pd)) != KCGI_OK || + (current && (status = breakform(pd))) != KCGI_OK || (status = printtimes(pd, times)) != KCGI_OK) { freetimesheet(times); return status;