#include <iostream.h>
#include <string.h>
#include <fstream.h>
#include "cgi.h"
void nospace(char *p)
{
	int c=0;
	while(p[c])
	{
		if(p[c]==' ')
		{
			int d=c;
			while(p[d+1])
			{
				p[d]=p[d+1];
				d++;
			}
			p[d]=0;
		}
		c++;
	}
}
void main()
{
	char in[10000];
	char name[128];
	char parent[128];
	char text[10000];
	char path1[256];
	char path2[256];
	char path3[256];
	Get(in);
	NextParam(in,name);
	NextParam(in,parent);
	NextParam(in,text);
	nospace(parent);
	
	strcpy(path1,"C:\\Program Files\\Lilhttp\\wwwroot\\profile\\guestbook\\");
	char *txt=".txt";
	strcat(path1,parent);
	strcat(path1,txt);
	ofstream n;
	n.open(path1, ios::app);
	n<<endl;
	n<<text;
	n.close();

	strcpy(path2,"guestlist.txt");
	//char *dat=".dat";
	//strcat(path2,parent);
	//strcat(path2,dat);
	
	char testln[256];			//So there are no duplicates in lists
	ifstream file;
	file.open(path2,ios::in);
	while(file.getline(testln,256))
	{
		if(strstr(testln,parent)) 
		{
			file.close();
			goto skiplist;
		}
	}
	file.close();
	
	n.open(path2, ios::app);
	n<<endl;
	n<<"<a href=\"http://www.zehder.com:88/profile/guestbook/"<<parent<<".htm\" target=\"_self\">"<<parent<<"</a> ("<<name<<")<br>";
	n.close();

skiplist:
	strcpy(path3,"C:\\Program Files\\Lilhttp\\wwwroot\\profile\\guestbook\\");
	char *htm=".htm";
	strcat(path3,parent);
	strcat(path3,htm);
	n.open(path3, ios::out);
	n<<"<html><body BGCOLOR='000000'><font face='Verdana' color='888888'><!-- #include=\"C:\\Program Files\\Lilhttp\\wwwroot\\profile\\guestbook\\"<<parent<<".txt\" --><br><br><A HREF=\"http://www.zehder.com:88/profile/guestbook/index.htm\" TARGET=\"_self\">| back |</A></font></body></html>";
	n.close();

	cout<<"<html><body bgcolor='black' text='green' link='green' vlink='green' active='green'><font face='Lucida Console' color='green' size='2'>File Saved</font></body></html>";
}
