Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

A C++ Embedded Web Server

, 23 Jun 2014 BSD
Give a C++ application its own web page
webem_demo.zip
code_project
examples
webemCalendar
calendar.dat
sqlite3.dll
webemCalendar.vcproj.CORVIS.james.user
webemHello
webemHello.vcproj.CORVIS.james.user
webemHelloForm
webemHelloForm.vcproj.CORVIS.james.user
webemMT
webemMT.vcproj.CORVIS.james.user
src
sqlite
sqlite3.lib
webem
server
Jamfile
Jamfile.v2
webem_src.zip
manifest
manifest.uuid
webem.fossil
_FOSSIL_
doc
DoxyFile
html
doxygen.png
tab_b.gif
tab_l.gif
tab_r.gif
examples
webemButton
webemCalendar
calendar.dat
sqlite3.dll
sqlite3.lib
WebemHello
webemHelloForm
server
 /* 
 * Copyright (c) 2008 by James Bremner
 * All rights reserved.
 *
 * Use license: Modified from standard BSD license.
 * 
 * Redistribution and use in source and binary forms are permitted
 * provided that the above copyright notice and this paragraph are
 * duplicated in all such forms and that any documentation, advertising 
 * materials, Web server pages, and other materials related to such
 * distribution and use acknowledge that the software was developed
 * by James Bremner. The name "James Bremner" may not be used to 
 * endorse or promote products derived from this software without 
 * specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 */

#include "stdafx.h"
#include "cWebemTable.h"
#include "../sqlite/sqlitedatabase.h"

cWebemTable::cWebemTable() 
		: myFlagReadTable(1),
		myName(0),
		pdb(0)
	{}

/**

  Generate HTML to display database table

  @return HML string to display table

  The table has a DELETE button.  When clicked on
  this will invoke the cWebem action table_<tablename>_action

*/
char * cWebemTable::Display()
{

	static string ret;
	char buf[1000];

	if( ! myName || !pdb ) {
		ret = "Table undefined";
		return (char*)ret.c_str();
	}
	ret.clear();
	// read table
	if( myFlagReadTable ) {
		sprintf(buf,"SELECT * FROM %s;", myName);
		myRowCount = pdb->Query( buf );
		if( myRowCount < 1 ) {
			ret = "Table ";
			ret += myName;
			ret += " is empty";
			return (char*)ret.c_str();
		}
	}

	//  DELETE button
	sprintf( buf,
		"<form name=form_table_%s method=GET action=\"table_%s_action.webem\">",
		myName, myName );
	ret = buf;
	ret += "<input type=submit value=\"DELETE\" ><p>";


	ret += "<table RULES=ALL FRAME=BOX CELLPADDING=5>";

	// column headers
	if ( myHeads.size() == myColCount ) {
		ret += "<tr><th></th>";
		for( int k = 0; k < myColCount; k++ ) {
			sprintf(buf,"<th>%s</th>",myHeads[k].c_str());
			ret += buf;
		}
		ret += "</tr>\n";
	}

	// loop over records, outputing s table row for each
	for( int k = 0; k < myRowCount; k++ ) {

		// set the rows to class oddrow and evenro alternately
		// so the html style can differentiate alternate rows
		if( k%2 )
			ret += "<tr CLASS=\"evenrow\">";
		else
			ret += "<tr CLASS=\"oddrow\">";

		// the selection radio button
		ret += "<td><input type=radio name=select value=";
		sprintf(buf,"\"%s\"",pdb->myRows[myColCount*k + 0].c_str());
		ret += buf;
		ret += "></td>";

		// the columns of data
		for ( int col=0; col < myColCount; col++ ) {
			ret += "<td>";
			ret += pdb->myRows[myColCount*k + col];
			ret += "</td>";
		}
		ret += "</tr>\n";
	}
	ret += "</table></form>";
	return (char*)ret.c_str();

}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The BSD License

Share

About the Author

ravenspoint
Founder Raven's Point Consulting
Canada Canada
No Biography provided

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.141216.1 | Last Updated 23 Jun 2014
Article Copyright 2008 by ravenspoint
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid