AmendHub

Download:

jcs

/

subtext

/

amendments

/

322

sysop: Add function to delete a message board

This does not delete the .brd file, just removes its record.

jcs made amendment 322 about 1 year ago
--- sysop.c Thu Feb 23 07:26:16 2023 +++ sysop.c Fri Feb 24 21:53:24 2023 @@ -124,6 +124,7 @@ void sysop_edit_boards(struct session *s) { static const struct session_menu_option opts[] = { + { 'd', "Dd", "Delete board" }, { 'n', "Nn", "Create new board" }, { 'q', "QqXx", "Return to sysop menu" }, { '?', "?", "List menu options" }, @@ -133,8 +134,8 @@ sysop_edit_boards(struct session *s) struct board *board, *new_board; struct bile *new_board_bile; size_t n, size; - short ret; - char c, *data = NULL; + short ret, id, sc; + char c, *data = NULL, *name; bool show_help = true; bool done = false; bool found = false; @@ -164,6 +165,47 @@ sysop_edit_boards(struct session *s) show_help = false; switch (c) { + case 'd': + /* TODO: move this to board edit menu */ + session_printf(s, "Board ID to delete: "); + session_flush(s); + + name = session_field_input(s, 5, 5, "", false, 0); + session_output(s, "\r\n", 2); + session_flush(s); + + if (name == NULL) + break; + id = atoi(name); + xfree(&name); + if (id == 0) + break; + + for (n = 0; n < db->nboards; n++) { + board = &db->boards[n]; + if (board->id != id) + continue; + + session_printf(s, + "Really delete board %s? [y/N] ", board->name); + session_flush(s); + + sc = session_input_char(s); + if (s->ending) + return; + if (sc != 'Y' && sc != 'y') + continue; + session_printf(s, "%c\r\n", sc == 'Y' ? 'Y' : 'y'); + session_flush(s); + + session_logf(s, "Deleting board %ld (%s)!", + board->id, board->name); + + db_board_delete(db, board); + db_cache_boards(db); + break; + } + break; case 'n': board = xmalloczero(sizeof(struct board), "sysop_edit_boards board"); @@ -265,7 +307,7 @@ sysop_edit_folders(struct session *s) while (!done && !s->ending) { /* * Unfortunately we have to do this every iteration because the - * list of boards may change + * list of folders may change */ if (dopts != NULL) xfree(&dopts);