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

173 lines
4.4 KiB
PHP

<?php
/** form for subscribing to the "Kulturschrift"
* @version 1.0.0
* @date 2007-11-25
* @author Martin Lenzelbauer
*/
require_once(ROOT."include/db.inc.php");
require_once(ROOT."cms/modules/ticketcustomer.class.php");
/** predefined entry point for the PHP script
* @return page content
*/
//-------------------------------
function doPhpScript(){
//-------------------------------
if(isset($_POST['submit'])){
if(isValid()){
send();
return printSuccess();
}
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['email'])){
$errors[] = "Bitte geben Sie Ihre E-Mail Adresse 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['address'])){
$errors[] = "Bitte geben Sie Ihre Wohnadresse an!";
}
return sizeof($errors) == 0;
}
/** prints the contact form
* @return string
*/
//----------------------------------------
function printForm(){
//----------------------------------------
global $errors;
$f = new Template(TEMPLATE_DIR."subparts/kulturschrift_subscribe.html");
$f->removeBlock("SUCCESS");
$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("PHONE", $_POST['phone']);
$f->setVar("EMAIL", $_POST['email']);
$f->setVar("ACAD", $_POST['acad']);
return $f->toString();
}
/** prints the success view
* @return string
*/
//------------------------------------------
function printSuccess(){
//------------------------------------------
$f = new Template(TEMPLATE_DIR."subparts/kulturschrift_subscribe.html");
$f->removeBlock("FORM");
return $f->toString();
}
/** sends the form data via e-mail
*/
//------------------------------------------
function send(){
//------------------------------------------
// send info mail
$to = "kulturhaus@bruckmuehle.at";
$subject = "Bestellung der Kulturschrift";
$headers = "From: kulturhaus@bruckmuehle.at\r\n";
$headers .= "Content-Type: text/plain; charset=\"utf-8\"\r\n";
$body = "Bestellung der Kulturschrift für:\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 .= "Telefon: $_POST[phone]\n";
$body .= "E-Mail: $_POST[mail]\n";
@mail($to, $subject, $body, $headers);
#@mail("mtd04041@fh-hagenberg.at", "Kopie: $subject", $body, $headers);
// save person to database
$p = new TicketCustomer();
$p->firstname = $_POST['firstname'];
$p->surname = $_POST['surname'];
$p->email = $_POST['email'];
$p->address = $_POST['address'];
$p->zip = $_POST['zip'];
$p->city = $_POST['city'];
$p->country = "";
$p->phone = $_POST['phone'];
$p->acad = $_POST['acad'];
switch($_POST['gender']){
case "Herr": $p->gender = "m"; break;
case "Frau": $p->gender = "f"; break;
default: $p->gender = "x";
}
$p->findInDatabase();
$p->save();
}
/** 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";
}
?>