Hallo zusammen,
Ich hatte in letzter Zeit einiges zu tun (Prüfungen...

) und habe mich desshalb nicht mehr gemeldet. Sorry!!
Wir haben das Modul von Andreas Linder erweitert. Ich weiss es ist nicht Perfekt, aber es Funktioniert bei uns gut.
Beschreibung:
Code: Alles auswählen
Kontaktformular anzeigen und eingegebene Daten per eMail verschicken
Author: Andreas Lindner
modified: mead / Mai 05
Input:
Code: Alles auswählen
?><?php
/***********************************************
* CONTENIDO MODUL - INPUT
*
* Modulname : Contact form
* Author(s) : Andreas Lindner
* Copyright : Contenido - four for business
* Created : 12.08.2005
************************************************/
?>
<table border="0">
<tr>
<td><?php echo mi18n("Absender EMail");?></td>
<td><input type="text" name="<?php echo "CMS_VAR[0]";?>" value="<?php echo "CMS_VALUE[0]"; ?>"></td>
</tr>
<tr>
<td><?php echo mi18n("Absender Name");?></td>
<td><input type="text" name="<?php echo "CMS_VAR[2]";?>" value="<?php echo "CMS_VALUE[2]"; ?>"></td>
</tr>
<tr>
<td><?php echo mi18n("Empfänger EMail");?></td>
<td><input type="text" name="<?php echo "CMS_VAR[1]";?>" value="<?php echo "CMS_VALUE[1]"; ?>"></td>
</tr>
<tr>
<td><?php echo mi18n("Betreff");?></td>
<td><input type="text" name="<?php echo "CMS_VAR[3]";?>" value="<?php echo "CMS_VALUE[3]"; ?>"></td>
</tr>
<?php
$c1 = '';
$c2 = '';
$c3 = '';
$c4 = '';
switch (strtolower("CMS_VALUE[4]")) {
case "smtp" :
$c1 = ' checked';
break;
case "mail" :
$c2 = ' checked';
break;
case "sendmail" :
$c3 = ' checked';
break;
case "qmail" :
$c4 = ' checked';
break;
default :
$c3 = ' checked';
}
?>
<tr>
<td valign="top"><?php echo mi18n("Mailer");?></td>
<td>
<input type="radio" name="<?php echo "CMS_VAR[4]";?>" value="mail"<?php echo $c2;?>> <?php echo mi18n("mail");?><br/>
<input type="radio" name="<?php echo "CMS_VAR[4]";?>" value="qmail"<?php echo $c4;?>> <?php echo mi18n("qmail");?><br/>
<input type="radio" name="<?php echo "CMS_VAR[4]";?>" value="sendmail"<?php echo $c3;?>> <?php echo mi18n("sendmail");?><br/>
<input type="radio" name="<?php echo "CMS_VAR[4]";?>" value="smtp"<?php echo $c1;?>> <?php echo mi18n("smtp");?><br/>
</td>
</tr>
<tr>
<td><?php echo mi18n("SMTP Host");?></td>
<td><input type="text" name="<?php echo "CMS_VAR[5]";?>" value="<?php echo "CMS_VALUE[5]"; ?>"></td>
</tr>
<tr>
<td><?php echo mi18n("SMTP User");?></td>
<td><input type="text" name="<?php echo "CMS_VAR[6]";?>" value="<?php echo "CMS_VALUE[6]"; ?>"></td>
</tr>
<tr>
<td><?php echo mi18n("SMTP Passwort");?></td>
<td><input type="text" name="<?php echo "CMS_VAR[7]";?>" value="<?php echo "CMS_VALUE[7]"; ?>"></td>
</tr>
</table>
<?php
Output:
Code: Alles auswählen
<?php
/***********************************************
* CONTENIDO MODUL - OUTPUT
*
* Modulname : Contact form
* Author(s) : Andreas Lindner
* Copyright : Contenido - four for business
* Created : 12.08.2005
************************************************/
#Includes
cInclude("classes","waldrand/class.captcha.php");
cInclude("classes", "class.phpmailer.php");
#Create new captcha
if (empty($_GET['session_code']))
{ $session_code = md5(round(rand(0,40000))); }
else
{ $session_code=$_GET['session_code']; }
$my_captcha = new captcha( $session_code, '_TEMP_' );
if (!isset ($_POST['send'])) {
#Form has not been sent yet
cInclude('classes', 'class.article.php');
cInclude('classes', 'class.template.php');
#Create contact form
echo '<form class="kontaktform" name="kontaktform" id="kontaktform" method="post" action="'.$sess->url("front_content.php?idcat=$idcat&idart=$idart&parentid=$parentid&session_code=$session_code").'">';
echo '<input type="hidden" name="send" value="1">';
if (!is_object($tpl)) {
$tpl = new Template;
}
$tpl->set("s", "ANREDE", mi18n("Anrede"));
$tpl->set("s", "ANREDE_OPTION1", mi18n("Herr"));
$tpl->set("s", "ANREDE_OPTION2", mi18n("Frau"));
$tpl->set("s", "NACHNAME", mi18n("Name"));
$tpl->set("s", "VORNAME", mi18n("Vorname"));
$tpl->set("s", "FIRMA", mi18n("Firma"));
$tpl->set("s", "STRASSE", mi18n("Strasse/Nr."));
$tpl->set("s", "PLZORT", mi18n("PLZ/Ort"));
$tpl->set("s", "TELEFON", mi18n("Telefon"));
$tpl->set("s", "EMAIL", mi18n("eMail"));
$tpl->set("s", "ANLIEGEN", mi18n("Nachricht"));
$tpl->set("s", "PFLICHTFELDER", mi18n("Pflichtfelder"));
$tpl->set("s", "ABSCHICKEN", mi18n("Abschicken"));
$tpl->set("s", "LOESCHEN", mi18n("Löschen"));
$tpl->set("s","CAPTCHA","Code:");
$tpl->set("s","PICT_URL",$my_captcha->get_pic(4));
$tpl->generate($cfgClient[$client]["path"]["frontend"]."templates/kontaktformular_waldrand.html");
echo '</form>';
} elseif ($_POST['send'] == 1) {
#Form has been sent
#Check user input
$noerrors = true;
$msg = '';
if ($my_captcha->verify($_POST['Captcha'])===false)
{
$noerrors = false;
$msg .= mi18n("Die eingegebene Kombination war leider falsch. Bitte geben Sie den code nochmals ein.")."<br/>";
}
if ($_POST['Vorname'] == '') {
$noerrors = false;
$msg .= mi18n("Bitte geben Sie Ihren Vornamen ein!")."<br/>";
}
if ($_POST['Nachname'] == '') {
$noerrors = false;
$msg .= mi18n("Bitte geben Sie Ihren Namen ein!")."<br/>";
}
if ($_POST['EMail'] == '') {
$noerrors = false;
$msg .= mi18n("Bitte geben Sie Ihre EMail-Adresse ein!")."<br/>";
}
if ($_POST['Strasse'] == '') {
$noerrors = false;
$msg .= mi18n("Bitte geben Sie Ihre Straße ein!")."<br/>";
}
if ($_POST['PLZOrt'] == '') {
$noerrors = false;
$msg .= mi18n("Bitte geben Sie Ihre PLZ/Ort ein!")."<br/>";
}
if ($noerrors == false) {
#Errors have been found
echo mi18n("<div class=\"text\"><h1>Fehler</h1><p>Beim Versenden sind folgende Fehler aufgetreten:</p>")."<p>";
echo $msg.'</p>';
echo '<a href="javascript:history.back();">'.mi18n("Zurück").'</a></div>';
} else {
#No errors, create and send mail
$mail = new phpmailer;
$mail_body = '<html><head></head><body> <table width="400"> ';
if (is_array($_POST)) {
foreach ($_POST as $key => $value) {
if ($key != 'send') {
$mail_body .= "<tr><td width='100'>$key</td><td>$value</td></tr> ";
}
}
}
$mail_body .= '</table></bo'.'dy></html>';
$mail->Host = "localhost";
$mail->IsHTML(true);
#Get mailer from settings
switch (strtolower("CMS_VALUE[4]")) {
case "smtp" :
$mail->IsSMTP();
$host = "CMS_VALUE[5]";
$user = "CMS_VALUE[6]";
$password = "CMS_VALUE[7]";
if (($host != '') && ($user != '') && ($password != '')) {
$mail-> $SMTPAuth = true;
$mail->Host = $host;
$mail->Username = $user;
$mail->Password = $password;
}
break;
case "mail" :
$mail->IsMail();
break;
case "sendmail" :
$mail->IsSendmail();
break;
case "qmail" :
$mail->IsQmail();
break;
default :
}
$mail->From = "CMS_VALUE[0]";
$mail->FromName = "CMS_VALUE[2]";
$mail->AddAddress("CMS_VALUE[1]", "");
$mail->Subject = "CMS_VALUE[3]";
$mail->Body = $mail_body;
$mail->WordWrap = 50;
$mail->Send();
#Display message after mail is sent
echo "<div class=\"text\"><h1>".mi18n("Besten Dank")."</h1><p>".mi18n("Ihr Anliegen wurde mir weitergeleitet. Vielen Dank!")."</p>
<p>".mi18n("Ich werde mit Ihnen baldmöglichst Kontakt aufnehmen.")."<br/> <br/>
Adrian Meier</p></div>";
}
}
?>
Zusätzlich braucht es noch die Folgende Klasse:
Code: Alles auswählen
<?php
/*
Jax Captcha Class v1.o1 - Copyright (c) 2005, Andreas John aka Jack (tR)
This program and it's moduls are Open Source in terms of General Public License (GPL) v2.0
class.captcha.php (captcha class module)
Last modification: 2005-09-05
*/
class captcha
{
var $session_key = null;
var $temp_dir = null;
var $width = 160;
var $height = 60;
var $jpg_quality = 15;
/**
* Constructor - Initializes Captcha class!
*
* @param string $session_key
* @param string $temp_dir
* @return captcha
*/
function captcha( $session_key, $temp_dir )
{
$this->session_key = $session_key;
$this->temp_dir = $temp_dir;
}
/**
* Generates Image file for captcha
*
* @param string $location
* @param string $char_seq
* @return unknown
*/
function _generate_image( $location, $char_seq )
{
$num_chars = strlen($char_seq);
$img = imagecreatetruecolor( $this->width, $this->height );
imagealphablending($img, 1);
imagecolortransparent( $img );
// generate background of randomly built ellipses
for ($i=1; $i<=200; $i++)
{
$r = round( rand( 0, 100 ) );
$g = round( rand( 0, 100 ) );
$b = round( rand( 0, 100 ) );
$color = imagecolorallocate( $img, $r, $g, $b );
imagefilledellipse( $img,round(rand(0,$this->width)), round(rand(0,$this->height)), round(rand(0,$this->width/16)), round(rand(0,$this->height/4)), $color );
}
$start_x = round($this->width / $num_chars);
$max_font_size = $start_x;
$start_x = round(0.5*$start_x);
$max_x_ofs = round($max_font_size*0.9);
// set each letter with random angle, size and color
for ($i=0;$i<=$num_chars;$i++)
{
$r = round( rand( 127, 255 ) );
$g = round( rand( 127, 255 ) );
$b = round( rand( 127, 255 ) );
$y_pos = ($this->height/2)+round( rand( 5, 20 ) );
$fontsize = round( rand( 18, $max_font_size) );
$color = imagecolorallocate( $img, $r, $g, $b);
$presign = round( rand( 0, 1 ) );
$angle = round( rand( 0, 25 ) );
if ($presign==true) $angle = -1*$angle;
$image_font = '../contenido/classes/waldrand/default.ttf';
ImageTTFText( $img, $fontsize, $angle, $start_x+$i*$max_x_ofs, $y_pos, $color, $image_font, substr($char_seq,$i,1) );
}
// create image file
imagejpeg( $img, $location, $this->jpg_quality );
flush();
imagedestroy( $img );
return true;
}
/**
* Returns name of the new generated captcha image file
*
* @param unknown_type $num_chars
* @return unknown
*/
function get_pic( $num_chars=8 )
{
// define characters of which the captcha can consist
$alphabet = array(
'A','B','C','D','E','F','G','H','I','J','K','L','M',
'N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
'1','2','3','4','5','6','7','8','9','0' );
$max = sizeof( $alphabet );
// generate random string
$captcha_str = '';
for ($i=1;$i<=$num_chars;$i++) // from 1..$num_chars
{
// choose randomly a character from alphabet and append it to string
$chosen = rand( 1, $max );
$captcha_str .= $alphabet[$chosen-1];
}
// generate a picture file that displays the random string
if ( $this->_generate_image( $this->temp_dir.'/'.'cap_'.md5( strtolower( $captcha_str )).'.jpg' , $captcha_str ) )
{
$fh = fopen( $this->temp_dir.'/'.'cap_'.$this->session_key.'.txt', "w" );
fputs($fh, md5(strtolower($captcha_str)));
return( md5( strtolower($captcha_str) ) );
}
else
{
return false;
}
}
/**
* check hash of password against hash of searched characters
*
* @param string $char_seq
* @return boolean
*/
function verify( $char_seq )
{
$fh = fopen( $this->temp_dir.'/'.'cap_'.$this->session_key.'.txt', "r" );
$hash = fgets( $fh );
$hash2 = md5(strtolower($char_seq));
if ($hash2 == $hash)
return true;
else
return false;
}
}
?>
Und die Ausgabe der Graphik:
Code: Alles auswählen
<?php
/*
Jax Captcha Class v1.o1 - Copyright (c) 2005, Andreas John aka Jack (tR)
This program and it's moduls are Open Source in terms of General Public License (GPL) v2.0
captcha_image.php (captcha image service)
Last modification: 2005-09-05
*/
$tmp_dir_path = $_SERVER["DOCUMENT_ROOT"]."/cms/_TEMP_/";
$captcha_expires_after = 420;
// deactivate Cache
header("Expires: Mon, 01 Jul 1990 00:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") ." GMT");
header("Pragma: no-cache");
header("Cache-Control: no-store, no-cache, max-age=0, must-revalidate");
header("Content-Type: image/jpeg", true);
if (!empty( $HTTP_GET_VARS['img'] ) )
$img = $HTTP_GET_VARS['img'];
else
{
echo 'no image file specified via &img=...';
exit;
}
if (!$fh = fopen( $tmp_dir_path.'cap_'.$img.'.jpg', 'rb'))
{
var_dump($_SERVER);
echo 'could not open image file!';
}
else
{
fpassthru( $fh );
fclose( $fh );
}
// clean up
$tmp_dir = dir( $tmp_dir_path );
while( $entry = $tmp_dir->read())
{
if ( is_file( $tmp_dir_path . $entry ) )
{
if ( mktime() - filemtime( $tmp_dir_path . $entry ) > $captcha_expires_after )
{
unlink( $tmp_dir_path . $entry );
}
}
}
?>
Wir brauchen dieser Font:
http://www.aedumeier.ch/contenido/class ... efault.ttf.
Dies ist unsere Gedankenstüze für die Inbetriebnahme:
Code: Alles auswählen
Benötigte Dateien:
------------------
In Ordner "cms/templates" (oder mit HTML Editor)
> HTML-Vorlage "kontaktformular_waldrand.html"
In Ordner "cms"
> captcha_image.php
In Ordner "contenido/classes/waldrand"
> class.captcha.php
> default.ttf
Ordner erstellen:
> cms/_TEMP_ ==> CHMOD 777 !!
Gruss Adrian