"); //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 = 'Sicherheitscode'; 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 .= '


'; //send notification $param_notify_content .= "\n\nVon: $f_name\nEmail: $f_mail\n\nDas wurde geschrieben:\n\n$f_ntry\n\nDas wars schon.\nViele Grüße, Dein Stefan."; mail("$recipient_guestbook_notify", "$param_notify_subject", "$param_notify_content", "From: $param_notify_alias <$sender_no_reply>\nReply-To: $sender_no_reply\nContent-Type: text/plain; charset=utf-8"); } else { if($database == true) { //output HTML: database error occured $html_output = $param_db_entry_error.mysql_error(); } } } }; //replace contactform specific content $html_output = str_replace("%FORM_ACTION%", $action_clean, $html_output); $html_output = str_replace("%FORM_COMMENT%", $param_form_comment, $html_output); $html_output = str_replace("%LABEL_NAME%", $param_label_name, $html_output); $html_output = str_replace("%LABEL_MAIL%", $param_label_mail, $html_output); $html_output = str_replace("%LABEL_URL%", $param_label_url, $html_output); $html_output = str_replace("%LABEL_ICQ%", $param_label_icq, $html_output); $html_output = str_replace("%LABEL_NTRY%", $param_label_ntry, $html_output); $html_output = str_replace("%ADVICE_REQUIRED%", $param_advice_requ, $html_output); $html_output = str_replace("%BTN_SUBMIT%", $param_btn_submit, $html_output); // savety section $html_output = str_replace("%SAVETY_CODENAME%" , $param_savety_codename, $html_output); $html_output = str_replace("%SAVETY_C_CODENAME%", $savety_c_codename, $html_output); $html_output = str_replace("%SAVETY_QUESTION%" , $param_savety_question, $html_output); $html_output = str_replace("%SAVETY_INPUT%" , $savety_input, $html_output); $html_output = str_replace("%SAVETY_CODE%" , $savety_code, $html_output); $html_output = str_replace("%C_NAME%", $c_name, $html_output); $html_output = str_replace("%C_MAIL%", $c_mail, $html_output); $html_output = str_replace("%C_URL%", $c_url, $html_output); $html_output = str_replace("%C_ICQ%", $c_icq, $html_output); $html_output = str_replace("%C_NTRY%", $c_ntry, $html_output); $html_output = str_replace("%F_NAME%", $f_name, $html_output); $html_output = str_replace("%F_MAIL%", $f_mail, $html_output); $html_output = str_replace("%F_URL%", $f_url, $html_output); $html_output = str_replace("%F_ICQ%", $f_icq, $html_output); $html_output = str_replace("%F_NTRY%", $f_ntry, $html_output); break; #}}} default: case "show": #{{{ //offizielle Ansicht fuer alle Besucher if($database == true) { $sql = "SELECT book_id, submitter, message, submdate, url, icq, status FROM guestbook WHERE status = 1 ORDER BY submdate DESC"; $result = mysql_query($sql); } else { // guestbook_actual exists or not // $fn = "guestbook_actual.txt"; $fn = "guestbook.txt"; $result = file_exists($fn); } if ($result) { //show book table header $html_output .= ''; $html_output .= ''. ''. ''. ''. '


'. '
'; $html_output .= '
'; $html_output .= '
'. ''. ''. ''. ''. ''; $html_output .= ''; $tabstyle = 0; if($database == true) { //{{{ database while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $imp_row = implode("|", $row); $exp_row = explode("|", $imp_row); //define table template for single rows $tablerow = ''. ''. ''. ''. ''. ''; //replace template variables by row values $tablerow = str_replace("%BOOKID%", $exp_row[1], $tablerow); $tablerow = str_replace("%SUBMITTER%", $exp_row[2], $tablerow); $tablerow = str_replace("%COMMENT%", $exp_row[3], $tablerow); $tablerow = str_replace("%TIMESTAMP%", $exp_row[4], $tablerow); if (($exp_row[5]<>"")&&($exp_row[5]!=" ")&&($exp_row[5]!=" ")) { $tablerow = str_replace("%URL%", "", $tablerow); } else { $tablerow = str_replace("%URL%", "
", $tablerow); }; if (($exp_row[6]<>"")&&($exp_row[6]!=" ")&&($exp_row[6]!=" ")) { $tablerow = str_replace("%ICQ%", "", $tablerow); } else { $tablerow = str_replace("%ICQ%", "
", $tablerow); }; if ($tabstyle % 2 == 0) { $tablerow = str_replace("%ROWCOLOR%", $rowstyle_bright, $tablerow); } else { $tablerow = str_replace("%ROWCOLOR%", $rowstyle_dark, $tablerow); }; //show book entries $html_output .= $tablerow; //change tabstyle $tabstyle++; } } //}}} else { //{{{ no database // copy file content in array structure $file_content = file("guestbook.txt"); // reverse array content (line based) or not if ($actual_top == true) { // most actual guestbook content on top $file_content = array_reverse($file_content); } // extract each filelines (line by line) while (list (, $fileline) = each ($file_content)) { if ($fileline != "") { // extract file line $exp_row = explode("&&", $fileline); // is online? if ($exp_row[1] == 1) { //define table template for single rows $tablerow = ''. ''. ''. ''. ''. ''; // replace template variables by row values $tablerow = str_replace("%BOOKID%", $exp_row[2], $tablerow); $tablerow = str_replace("%SUBMITTER%", $exp_row[3], $tablerow); $tablerow = str_replace("%COMMENT%", $exp_row[5], $tablerow); $tablerow = str_replace("%DATESTAMP%", "Eingetragen am: ".$exp_row[8], $tablerow); $tablerow = str_replace("%TIMESTAMP%", "Zeit:".$exp_row[9]." Uhr", $tablerow); $tablerow = str_replace("%EMAIL%", $exp_row[4], $tablerow); // fill URL column if (($exp_row[6]<>"")&&($exp_row[6]!=" ")&&($exp_row[6]!=" ")) { $tablerow = str_replace("%URL%", "", $tablerow); } else { $tablerow = str_replace("%URL%", "
", $tablerow); }; // fill ICQ column $v_icq = str_replace("-", "", $exp_row[7]); $v_icq = str_replace("/", "", $v_icq); $v_icq = str_replace(" ", "", $v_icq); $v_icq = str_replace(" ", "", $v_icq); if ($v_icq!=0) { $tablerow = str_replace("%ICQ%", "", $tablerow); } else { //$tablerow = str_replace("%ICQ%", "", $tablerow); $tablerow = str_replace("%ICQ%", "
", $tablerow); }; // set row color if ($tabstyle % 2 == 0) { $tablerow = str_replace("%ROWCOLOR%", $rowstyle_bright, $tablerow); } else { $tablerow = str_replace("%ROWCOLOR%", $rowstyle_dark, $tablerow); }; //show book entries $html_output .= $tablerow; //change tabstyle $tabstyle++; } } } } //}}} //show book table footer $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 .= '
%SUBMITTER%
%TIMESTAMP%
'. '
%URL%

'. '
%ICQ%

'. '
%COMMENT%

'. '
%SUBMITTER%

%DATESTAMP%
%TIMESTAMP%
'. '
%URL%

'. '
%ICQ%

'. '
%COMMENT%

'. '

'; $html_output .= ''. ''. ''. ''. '


'. '
'; $html_output .= '
'; } else { if($database == true) { $html_output .= $prefix.mysql_error().$postfix; } else{ } } break; #}}} } return ($html_output); } ?>