Files
bm/public_html/public/php/kulturcard.php
2025-09-24 13:26:28 +02:00

228 lines
5.8 KiB
PHP

<?php
/** kulturcard order form
* @version 1.1.0
* @date 2009-02-08
* @author Martin Lenzelbauer
*/
/** predefined entry point for the PHP script
* @return page content
*/
//-------------------------------
function doPhpScript(){
//-------------------------------
if(isset($_POST['submit'])){
if(isValid()){
if(!isSpam()){
$id = prepareInsert();
sendMailToOffice($id);
return printSuccess();
}
return printSpam();
}
return printForm();
}
return printForm();
}
/** checks if the entered form data is valid
* @return true, if the data is valid
*/
//----------------------------------
function isValid(){
//----------------------------------
global $errors;
$errors = array();
if(empty($_POST['firstname'])){
$errors[] = "Bitte geben Sie Ihren Vornamen an!";
}
if(empty($_POST['surname'])){
$errors[] = "Bitte geben Sie Ihren Nachnamen an!";
}
if(empty($_POST['zip'])){
$errors[] = "Bitte geben Sie Ihre Postleitzahl an!";
}
if(empty($_POST['city'])){
$errors[] = "Bitte geben Sie Ihren Wohnort an!";
}
if(empty($_POST['street'])){
$errors[] = "Bitte geben Sie Ihre Wohnadresse an!";
}
return sizeof($errors) == 0;
}
/** checks if the entered form data is spam
* @return true, if the data is spam
*/
//----------------------------------------
function isSpam(){
//----------------------------------------
// check time
$time = time();
if(!isset($_POST['time'])){ // time has been unset by the spambot
return true;
}
if(!is_numeric($_POST['time'])){ // time has been manipulated by the spambot
return true;
}
if($time - $_POST['time'] < 3){ // user needed less than 3 seconds to fill the form -> spam
return true;
}
if($time - $_POST['time'] > 12 * 3600){ // user needed more than 12 hours to fill the form -> spam
return true;
}
// check baits
if(!empty($_POST['email'])){
return true;
}
if(!empty($_POST['url'])){
return true;
}
return false;
}
/** prints the contact form
* @return string
*/
//----------------------------------------
function printForm(){
//----------------------------------------
global $errors;
$f = new Template(TEMPLATE_DIR."subparts/kulturcard.html");
$f->removeBlock("SUCCESS");
$f->removeBlock("SPAM");
$f->setVar("ACTION", getCurrentUrl());
if(sizeof($errors) > 0){
$e = "<strong>FEHLER:</strong><ul>";
foreach($errors as $i){
$e .= "<li>$i</li>";
}
$e .= "</ul>";
$f->setVar("ERRORS", $e);
}
else{
$f->setVar("ERRORS", "&nbsp;");
}
if($_POST['gender'] == "Frau"){
$f->setVar("GENDER_F", "selected=\"selected\"");
$f->setVar("GENDER_M", "");
}
else{
$f->setVar("GENDER_M", "selected=\"selected\"");
$f->setVar("GENDER_F", "");
}
if(isset($_POST['info'])){
$f->setVar("INFO", "checked=\"checked\"");
}
else{
$f->setVar("INFO", "");
}
$f->setVar("FIRSTNAME", $_POST['firstname']);
$f->setVar("SURNAME", $_POST['surname']);
$f->setVar("STREET", $_POST['street']);
$f->setVar("ZIP", $_POST['zip']);
$f->setVar("CITY", $_POST['city']);
$f->setVar("MAIL", $_POST['mail']);
$f->setVar("TIME", time());
return $f->toString();
}
/** prints the success view
* @return string
*/
//------------------------------------------
function printSuccess(){
//------------------------------------------
$f = new Template(TEMPLATE_DIR."subparts/kulturcard.html");
$f->removeBlock("FORM");
$f->removeBlock("SPAM");
return $f->toString();
}
/** prints the spam view
* @return string
*/
//------------------------------------------
function printSpam(){
//------------------------------------------
$f = new Template(TEMPLATE_DIR."subparts/kulturcard.html");
$f->removeBlock("FORM");
$f->removeBlock("SUCCESS");
return $f->toString();
}
/** sends the form data via e-mail
* @param id proposed kulturcard id
*/
//------------------------------------------
function sendMailToOffice($id){
//------------------------------------------
$to = "kulturhaus@bruckmuehle.at";
$subject = "Bestellung Kulturcard";
$headers = "From: kulturhaus@bruckmuehle.at\r\n";
$headers .= "Content-Type: text/plain; charset=\"utf-8\"\r\n";
$body = "Kundendaten:\n\n";
$body .= "Anrede: $_POST[gender]\n";
$body .= "Vorname: $_POST[firstname]\n";
$body .= "Nachname: $_POST[surname]\n";
$body .= "Straße: $_POST[street]\n";
$body .= "PLZ: $_POST[zip]\n";
$body .= "Ort: $_POST[city]\n";
$body .= "E-Mail: $_POST[mail]\n";
$body .= "KuKa-Nummer: $id\n\n";
$body .= "Klicken Sie auf folgenden Link, um die Kulturcard mit diesen Inhaberdaten in die Datenbank zu speichern: ";
$body .= "http://bruckmuehle.at/tickets/culturecard.php?action=add&id=$id ";
@mail($to, $subject, $body, $headers);
}
/** prepares an insert statement
* @return id proposed kulturcard id
*/
//--------------------------------------------
function prepareInsert() {
//--------------------------------------------
$query = sprintf("SELECT MAX(id) FROM bruckm_ticketculturecard");
$result = dbQuery($query);
$line = mysqli_fetch_array($result, MYSQLI_ASSOC);
$count = intval(substr($line['MAX(id)'], -3, 3));
$id = sprintf("%09d%3d", date("ymd"), $count + 1);
$query = sprintf("INSERT INTO bruckm_ticketculturecard (id, owner, zip, city, address, tickets) VALUES (%d, %s, %d, %s, %s, 5)",
sqlnum($id),
sqlstring($_POST['firstname'] . " " .$_POST['surname']),
sqlnum($_POST['zip']),
sqlstring($_POST['city']),
sqlstring($_POST['street']));
$f = fopen("tickets/" . $id . ".sql", "w");
fwrite($f, $query);
fclose($f);
return $id;
}
/** converts the $_POST value to "ja" or "nein"
* @param value checkbox value
* @return "ja" or "nein"
*/
//--------------------------------------------
function yesOrNo($value){
//--------------------------------------------
if(isset($value) && !empty($value)){
return "ja";
}
return "nein";
}
?>