Add print view

main
cel 5 years ago
parent 94534fed18
commit 1723009e26
Signed by: cel
GPG Key ID: C28D95BB012367EA

@ -161,7 +161,10 @@ static int write_zet_link(int fd, const char *id, const char *title) {
}
static int write_topbar(int fd, enum page page, const char *id, const char *title) {
int rc = write_buf(fd, "<form action=\"search\">");
int rc = write_buf(fd,
"<table style=\"width:100%; border-collapse:collapse\"><tr>"
"<td style=\"padding:0\">"
"<form action=\"search\">");
rc |= write_buf(fd, " ");
if (page == PAGE_ALL) rc |= write_buf(fd, "<strong>");
@ -188,9 +191,14 @@ static int write_topbar(int fd, enum page page, const char *id, const char *titl
if (page == PAGE_ZET) {
rc |= write_zet_link(fd, id, title);
rc |= write_buf(fd, "</form></td>");
rc |= write_buf(fd, "<td style=\"text-align:right; padding:0;\">"
"<a href=\"?print\">print</a></td>");
} else {
rc |= write_buf(fd, "</form></td>");
}
rc |= write_buf(fd, "</form>");
rc |= write_buf(fd, "</tr></table>");
return rc;
}
@ -828,27 +836,35 @@ static int dpi_serve_zet(int fd, char *path) {
"</style>"
"</head>");
rc |= write_buf(fd, "<body style=\"margin:0\">");
rc |= write_topbar(fd, PAGE_ZET, id, title);
rc |= dprintf(fd,
"<table style=\"width:100%%; height:100%%; border-collapse:collapse\"><tr>"
"<td style=\"width:50%%\"><form method=post action=\"%s%s\" enctype=\"multipart/form-data\" style=\"height:100%%\">"
"<textarea name=text cols=64 rows=%d style=\"width:100%%\">\n"
, server_url, id, rows);
rc = passthrough_note_html(fd, note_fd);
if (rc < 0) { warnx("passthrough_note_html"); close(fd); return 0; }
rc = dprintf(fd, "</textarea><br>"
"<input type=submit value=\"Save\">"
" <input type=submit name=add_new_id value=\"Add New ID\">"
"</form></td>"
"<td>"
);
if (rc < 0) { warn("dpi_send_header"); close(fd); return 0; }
if (note_fd >= 0) rc = lseek(note_fd, 0, SEEK_SET);
if (rc < 0) {
rc = dprintf(fd, "\n<strong>Error</strong>: %s", strerror(errno));
if (rc < 0) warnx("dprintf");
close(fd);
// TODO: iterate
bool print = query != NULL && strncmp(query, "print", 5) == 0
&& (query[5] == '\0' || query[5] == '&' ||
(query[5] == '=' && !(query[6] == '\0' || query[6] == '&')));
if (!print) {
rc |= write_buf(fd, "<body style=\"margin:0\">");
rc |= write_topbar(fd, PAGE_ZET, id, title);
rc |= dprintf(fd,
"<table style=\"width:100%%; height:100%%; border-collapse:collapse\"><tr>"
"<td style=\"width:50%%\"><form method=post action=\"%s%s\" enctype=\"multipart/form-data\" style=\"height:100%%\">"
"<textarea name=text cols=64 rows=%d style=\"width:100%%\">\n"
, server_url, id, rows);
rc = passthrough_note_html(fd, note_fd);
if (rc < 0) { warnx("passthrough_note_html"); close(fd); return 0; }
rc = dprintf(fd, "</textarea><br>"
"<input type=submit value=\"Save\">"
" <input type=submit name=add_new_id value=\"Add New ID\">"
"</form></td>"
"<td>"
);
if (rc < 0) { warn("dpi_send_header"); close(fd); return 0; }
if (note_fd >= 0) rc = lseek(note_fd, 0, SEEK_SET);
if (rc < 0) {
rc = dprintf(fd, "\n<strong>Error</strong>: %s", strerror(errno));
if (rc < 0) warnx("dprintf");
close(fd);
}
} else {
rc |= write_buf(fd, "<body>");
}
char *text = note_fd >= 0 ? read_full(note_fd) : NULL;
@ -882,11 +898,16 @@ static int dpi_serve_zet(int fd, char *path) {
rc = write_all(fd, ob->data, ob->size);
if (rc < 0) warn("write_all");
bufrelease(ob);
rc = dprintf(fd, "</td></tr>");
if (rc < 0) warn("dprintf");
if (!print) {
rc = dprintf(fd, "</td></tr>");
if (rc < 0) warn("dprintf");
rc = dprintf(fd, "<tr><td></td><td>");
if (rc < 0) warn("dprintf");
rc = dprintf(fd, "<tr><td></td><td>");
if (rc < 0) warn("dprintf");
} else {
rc = write_buf(fd, "<br>");
if (rc < 0) warn("write_all");
}
struct zet_search zs;
bool first = true;
rc = zet_search_start(&zs, id, NULL);
@ -916,12 +937,16 @@ static int dpi_serve_zet(int fd, char *path) {
rc |= write_buf(fd, "</a></li>");
} while (1);
if (!first) (void)dprintf(fd, "</ul>");
rc = dprintf(fd, "</td></tr>");
if (rc < 0) warn("dprintf");
if (!print) {
rc = dprintf(fd, "</td></tr>");
if (rc < 0) warn("dprintf");
}
(void)zet_search_close(&zs);
rc = write_buf(fd, "</table>");
if (rc < 0) warn("write_buf");
if (!print) {
rc = write_buf(fd, "</table>");
if (rc < 0) warn("write_buf");
}
rc = write_buf(fd, "</body></html>");
if (rc < 0) warn("write_buf");

Loading…
Cancel
Save