Skip to content

Commit

Permalink
Merge branch 'main' of github.com:jmvsenterprise/crvr
Browse files Browse the repository at this point in the history
  • Loading branch information
jmvsenterprise committed Feb 10, 2024
2 parents b9d28fa + 46e6da6 commit 59f6535
Showing 1 changed file with 92 additions and 1 deletion.
93 changes: 92 additions & 1 deletion asl/asl2.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ static int save_question(struct question *question);
static int send_select_quiz_page(int client);
static int send_quiz_complete_page(int client);
static int send_quiz_page(int client);
static int quiz_is_done(struct quiz *quiz);
static int write_card_record(int fd, const struct card_record *record);
static int write_data_with_ref(int temp_file, FILE *quiz_file,
struct quiz *quiz);
Expand Down Expand Up @@ -535,6 +534,98 @@ save_question(struct question *question)
return err;
}

static int
send_quiz_complete_page(int client)
{
static const char html[] =
"<!DOCTYPE html>"
"<html>"
" <head><title>QUIZ COMPLETE</title></head>"
" <body>"
" <h1>Quiz Complete!</h1>"
" <p>You viewed %i cards!</p>"
" </body>"
"</html>";
if (dprintf(client, html, s_quiz->cards_reviewed) < 0) {
fprintf(stderr, "%s: Failed to send html: %i\n", __func__,
errno);
if errno ? errno : EIO;
}
return 0;
}

static int
send_quiz_page(int client)
{
static const char html[] =
"<!DOCTYPE html>"
"<html>"
" <head><title>ASL Quizzer</title></head>"
" <script type=\"text/javascript\">"
" function reveal() {"
" var back_div = document.getElementById(\"back_div\");"
" back_div.style.display = \"block\""
" document.getElementById(\"reveal_btn\").style.display = "
" \"none\";"
" }"
" </script>"
" <body>"
" <h1>ASL Quizzer</h1>"
" <p>Remaining Cards: %lu</p>"
" <div id=\"front_div\">"
" <h2>Front</h2>"
" <p>"
" %s"
" <p>"
" <p>"
" <input type=\"button\" id=\"reveal_btn\""
" name=\"reveal\" onclick=\"reveal()\""
" value=\"Reveal\">"
" <p>"
" </div>"
" <div id=\"back_div\" style=\"display:none;\">"
" <h2>Back</h2>"
" %s"
" <p>How confident were you?</p>"
" <form method=\"post\" action=\"/asl.html\">"
" <input type=\"submit\" name=\"button\""
" id=\"poor_button\" value=\"poor\">"
" <input type=\"submit\" name=\"button\""
" id=\"good_button\" value=\"good\">"
" <input type=\"submit\" name=\"button\""
" id=\"great_button\" value=\"great\">"
" </form>"
" </div>"
" </body>"
"</html>";

assert(s_quiz);
struct question *question = s_quiz->questions +
s_quiz->current_question;

// Send the question
struct card *card = question->card;
char buf1[PATH_MAX];
char buf2[PATH_MAX];
char *front = buf1;
char *back = buf2;
snprintf(buf1, PATH_MAX - 1, "<img src=\"%s\" \\>", card->path);
strncpy(buf2, card->path, PATH_MAX - 1);
if (!question->front) {
char *tmp = back;
back = front;
front = tmp;
}

if (dprintf(client, html, remaining_questions(s_quiz), front, back) < 0)
{
fprintf(stderr, "%s: Failed to send html for question %s: %i\n",
__func__, card->path, errno);
return errno ? errno : EIO;
}
return 0;
}

static int
write_card_record(int fd, const struct card_record *record)
{
Expand Down

0 comments on commit 59f6535

Please sign in to comment.