File: gbook.c

package info (click to toggle)
libcgi 1.0-5
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 940 kB
  • ctags: 268
  • sloc: sh: 2,700; ansic: 2,134; makefile: 232
file content (71 lines) | stat: -rw-r--r-- 1,394 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <stdio.h>
#include <time.h>
#include <cgi.h>

// File to write the messages
#define GBOOK "/tmp/libcgi_gbook.html"

void show_comments()
{
	// stupid code :)
	cgi_include(GBOOK);
}

char *now()
{
	struct tm *now;
	time_t now_time_t;
	char *buffer;

	now_time_t = time(NULL);
	now = localtime(&now_time_t);

	buffer = asctime(now);

	return buffer;
}

void example_description()
{
	puts(" LibCGI Examples - Extreme simple GuestBook<br> "
	"This example shows how to use cgi_include() function to show the<br>"
	"user some HTML data contained in another file. <br><br>");
}

int main()
{	
	cgi_init();
	cgi_process_form();	
	cgi_init_headers();

	example_description();

	if (cgi_param("action")) {
		// write the msg to the file
		FILE *fp;

		fp = fopen(GBOOK, "a");
		if (!fp) 
			cgi_fatal("Failed to open guestbook file for appending");

		fseek(fp, 0, SEEK_SET);

		fprintf(fp, "<b>Date:</b> %s<br>", now());
		fprintf(fp, "<b>Name:</b> %s<br>", cgi_param("name"));
		fprintf(fp, "<b>E-Mail: </b>%s<br>", cgi_param("email"));
		fprintf(fp, "<b>Message: </b>%s<br><br>", cgi_param("msg"));

		fclose(fp);
	}

	puts("<html><head><title>LibCGI examples - GuestBook</title></head><body>");
	cgi_include("table_add_comments.html");
	puts("<table width='70%' align='center' border='0'><tr><td>");

	show_comments();

	puts("</td></tr></table></body></html>");
	
	cgi_end();
	return 0;
}