timekeeper

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

commit 1de874bd4104c19e1faab11f1695b7512291421c
parent 268addc62aff8840d8871d162decc62c33586238
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date:   Sun, 24 Mar 2024 09:24:58 -0700

Separate header from tk_header into two parts

The second part is user stuff like login/logout and account management
links, the first is everything else (primarily links to various
functions of the timekeeper system itself when logged in, like the
times and archive pages).

Diffstat:
Mpages/common.c | 87+++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------
1 file changed, 56 insertions(+), 31 deletions(-)

diff --git a/pages/common.c b/pages/common.c @@ -5,47 +5,72 @@ #include "pages.h" enum kcgi_err -tk_header(struct pagedata *pd) +linkpage(struct pagedata *pd, int page, char *names[PageMax]) { - static int unauth_pages[] = { PageIndex, PageLogin, -1 }; - static int auth_pages[] = { - PageIndex, PageMain, PageArchive, PageAccount, PageLogout, -1 - }; - static char *pagenames[PageMax] = { - [PageIndex] = "Home" - }; - - enum kcgi_err status; - int *pages; - unsigned int i; - char namebuf[32]; char *url; + char namebuf[32]; + enum kcgi_err status; - if ((status = khtml_elem(&pd->html, KELEM_NAV)) != KCGI_OK || - (status = khtml_elem(&pd->html, KELEM_UL)) != KCGI_OK) + url = pd->pages[page]; + if (names[page]) { + strcpy(namebuf, names[page]); + } else { + strcpy(namebuf, url); + namebuf[0] = toupper(namebuf[0]); + } + + if ((status = khtml_elem(&pd->html, KELEM_LI)) != KCGI_OK || + (status = htmllink(pd, url, namebuf)) != KCGI_OK || + (status = khtml_closeelem(&pd->html, 1)) != KCGI_OK) return status; + return KCGI_OK; +} - if (pd->user) - pages = auth_pages; - else - pages = unauth_pages; +enum kcgi_err +linkpages(struct pagedata *pd, int *pages, char *names[PageMax]) +{ + unsigned int i; + enum kcgi_err status; + + if ((status = khtml_elem(&pd->html, KELEM_UL)) != KCGI_OK) + return status; for (i = 0; pages[i] >= 0; ++i) { - url = pd->pages[pages[i]]; - if (pagenames[i]) { - strcpy(namebuf, pagenames[i]); - } else { - strcpy(namebuf, url); - namebuf[0] = toupper(namebuf[0]); - } - - if ((status = khtml_elem(&pd->html, KELEM_LI)) != KCGI_OK || - (status = htmllink(pd, url, namebuf)) != KCGI_OK || - (status = khtml_closeelem(&pd->html, 1)) != KCGI_OK) + status = linkpage(pd, pages[i], names); + if (status != KCGI_OK) return status; } - return khtml_closeelem(&pd->html, 2); + return khtml_closeelem(&pd->html, 1); +} + +enum kcgi_err +tk_header(struct pagedata *pd) +{ + static char *pagenames[PageMax] = { + [PageIndex] = "Home" + }; + static int auth_a[] = { PageIndex, PageMain, PageArchive, -1 }; + static int auth_b[] = { PageAccount, PageLogout, -1 }; + static int unauth_a[] = { PageIndex, -1 }; + static int unauth_b[] = { PageLogin, -1 }; + + enum kcgi_err status; + int *a, *b; + + if (pd->user) { + a = auth_a; + b = auth_b; + } else { + a = unauth_a; + b = unauth_b; + } + + if ((status = khtml_elem(&pd->html, KELEM_NAV)) != KCGI_OK || + (status = linkpages(pd, a, pagenames)) != KCGI_OK || + (status = linkpages(pd, b, pagenames)) != KCGI_OK) + return status; + return khtml_closeelem(&pd->html, 1); } enum kcgi_err