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

Loading…
Cancel
Save