//database connection
function fnc_dbconnect($param_hostname, $param_username, $param_password, $param_database)
{
// connect the database server
$db = mysql_pconnect($param_hostname, $param_username, $param_password)
or die ("Connection to the database failed: ".mysql_error()."\n
");
//if db can be connected -> select it
if ($db)
{
mysql_select_db($param_database);
return true;
}
//otherwise show error message
else
{
echo "Database could not be selected: ".mysql_error()."\n
";
return false;
}
}
//validation of email format
function validateMAIL($param_MAIL)
{
// prüft, ob die E-Mail-Adresse gültig ist.
if (!eregi("^.+@.+\\..+$", $param_MAIL))
{ return false; }
else
{ return true; }
}
//the main function
function fnc_guestbook($scode_form, $scode_ses,
$param_savety_codename, $param_savety_question,
$param_hostname, $param_username, $param_password,
$param_database, $param_lang, $param_action,
$param_mode, $param_filled, $param_form_error,
$param_mail_invalid, $param_db_entry_error,
$param_form_comment, $param_form_thanks,
$param_label_name, $param_label_mail,
$param_label_url, $param_label_icq, $param_label_ntry,
$param_advice_requ, $param_btn_submit, $f_name,
$f_mail, $f_url, $f_icq, $f_ntry, $color_normal,
$color_marked, $rowstyle_bright, $rowstyle_dark,
$rowstyle_head, $linestyle, $param_name, $param_url,
$param_icq, $param_comment, $param_top,
$recipient_guestbook_notify, $sender_no_reply,
$param_notify_alias, $param_notify_subject,
$param_notify_content)
{
$html_output = '';
//include some necessary files
include "includes/config.cfg.php"; //load config data
// connect to store selection
if($database == true) {
// database connection
fnc_dbconnect($param_hostname, $param_username, $param_password, $param_database);
}
else {
// file connection
}
$prefix = '';
$postfix = '';
// mode related logic
switch($param_mode)
{
case "add": #{{{
//GENERAL
$guestbook_file = "includes/guestbook.htm.php";
$guestbook_template = fread(fopen($guestbook_file, "r"), filesize($guestbook_file));
// savety picture line inclusion
$savety_code = '';
if($param_filled!="yes")
{
//define colors (normal)
$c_name = $color_normal;
$c_mail = $color_normal;
$c_url = $color_normal;
$c_icq = $color_normal;
$c_ntry = $color_normal;
$savety_c_codename = $color_normal;
//embed HTML
$html_output .= $guestbook_template;
}
else
{
//check parameters (if => redraw form, else => thanks)
if(($f_name=="")||($f_ntry=="")||(($f_mail!="")&&(validateMAIL($f_mail)==false))||($scode_form != $scode_ses))
{
$tmp = '';
if($f_name==""){$c_name = $color_marked; $tmp = $param_form_error;} else{$c_name = $color_normal;}
if($f_ntry==""){$c_ntry = $color_marked; $tmp = $param_form_error;} else{$c_ntry = $color_normal;}
if(($f_mail!="")&&(validateMAIL($f_mail)==false)) {
$c_mail = $color_marked;
$tmp .= $param_mail_invalid;
}
else {
$c_mail = $color_normal;
}
// error mark safety code
if ($scode_form != $scode_ses){
$savety_c_codename = $color_marked;
$tmp = $param_error;
}
else
$savety_c_codename = $color_normal;
$c_url = $color_normal;
$c_icq = $color_normal;
if ($tmp != "") {
$param_form_comment = $tmp;
}
//embed HTML
$html_output .= $guestbook_template;
}
else
{
//write entry into database
$f_name = substr($f_name, 0, 50);
$f_mail = substr($f_mail, 0, 100);
$f_ntry = substr($f_ntry, 0, 2000);
$f_url = substr($f_url, 0, 100);
$f_icq = substr($f_icq, 0, 15);
$f_date = date("d.m.Y");
$f_time = date("G:i:s");
if($database == true) {
// build query string
$querystring = "INSERT INTO guestbook (submitter, subemail,
message, url, icq, status) VALUES ".
"('".$f_name."','".$f_mail."','".$f_ntry.
"','".$f_url."','".$f_icq."',0)";
// mySQL request
$result = mysql_query($querystring);
}
else { // no database available
// set change content
$change_content = 0;
// set content online or offline
$onoffline = 0;
$f_time_date = $f_date.$f_time;
$f_time_date = ereg_replace("\.", "", $f_time_date);
$f_time_date = ereg_replace("\:", "", $f_time_date);
$entry_valid = md5($f_time_date);
// open guestbook file and logfile (appended)
$fp = fopen("guestbook.txt","a");
// lock file
flock($fp,2);
// prepare entry for save
// strip slashes and HTML tags
$f_ntry = stripslashes($f_ntry);
$f_ntry = strip_tags($f_ntry);
// replace some whitespaces and special characters
$f_ntry = ereg_replace("$", "", $f_ntry);
$f_ntry = ereg_replace("\n", "
", $f_ntry);
$f_ntry = ereg_replace("\r", "", $f_ntry);
$f_ntry = ereg_replace("\\\\\\\"", "\"", $f_ntry);
// collect data of guestbook entry
$result = $change_content."&&".$onoffline."&&".$entry_valid."&&".
$f_name."&&".$f_mail."&&".$f_ntry."&&".$f_url."&&".
$f_icq."&&".$f_date."&&".$f_time."\n";
// save into file
fputs ($fp, $result);
// unlock file
flock($fp,3);
// close file
fclose($fp);
}
if ($result==true) {
// output HTML: thanks for guest entry
$html_output = $param_form_thanks;
// output HTML: add submenu
$html_output .= '
| '; $html_output .= ' | '. '
| '; $html_output .= $param_name; $html_output .= ' | '. ''; $html_output .= $param_url; $html_output .= ' | '. ''; $html_output .= $param_icq; $html_output .= ' | '. ''; $html_output .= $param_comment; $html_output .= ' | '; $html_output .= '
|
%SUBMITTER% %TIMESTAMP% '. ' | '.
'%URL% '. ' | '.
'%ICQ% '. ' | '.
'%COMMENT% '. ' | '.
'
|
%SUBMITTER% %DATESTAMP% %TIMESTAMP% '. ' | '.
'%URL% '. ' | '.
'%ICQ% '. ' | '.
'%COMMENT% '. ' | '.
'
| '; $html_output .= ' | '. '