Commits vergleichen

...

10 Commits

Autor SHA1 Nachricht Datum
o.pinke
cb6d0140a7 updates for V1.0.0 2025-07-28 09:44:27 +02:00
o.pinke
381994a727 add .gitattributes 2025-07-28 09:14:14 +02:00
o.pinke
cb811303c7 renaming and cleanup 2025-07-28 09:08:55 +02:00
o.pinke
79a1035feb gitadmin 2025-07-28 08:40:26 +02:00
o.pinke
3442027a78 add module xml 2025-07-28 08:34:55 +02:00
8014fe1169 add fields, use new ui class 2024-08-27 12:29:08 +02:00
eb1bbdbc95 token use not allowed in modules 2024-08-23 15:01:17 +02:00
14de75762d fix captcha, add type email, add new attributes, cleanup some code 2024-08-23 14:21:02 +02:00
0be23bcd33 update phpdoc and remove unneeded tags 2024-08-22 12:41:17 +02:00
5888026236 add org code and modify output 2024-08-14 20:00:56 +02:00
10 geänderte Dateien mit 367 neuen und 1258 gelöschten Zeilen

5
.gitattributes gevendort Normale Datei
Datei anzeigen

@ -0,0 +1,5 @@
.gitattributes export-ignore
.gitignore export-ignore
.project export-ignore
/nbproject export-ignore
phpdoc.dist.xml export-ignore

3
.gitignore gevendort
Datei anzeigen

@ -8,5 +8,4 @@ dist/
nbdist/
.nb-gradle/
/php/cl_contactform_output_Dodger.php
/php/cl_contactform_input_Dodger.php
/.dev/

Datei anzeigen

@ -1,3 +1,10 @@
# module-cl-contactform
# Module CL Contact Form
contactform module based on w3concepts.form.v1
contact form module based on module w3concepts.form.v1.
I'm still working on new documentation. Meanwhile, you may use the documentation from original module.
See https://forum.contenido.org/viewtopic.php?f=110&t=5066&hilit=w3concepts.form.v1
If you want to use captcha, you need to download securimage 4.0.2 and install it in folder cms/securimage
Download https://github.com/dapphp/securimage/releases/tag/4.0.2
Be aware that this version may not be compatible to PHP 8.x. I am working on a compatible version.

31
cl_module.xml Normale Datei
Datei anzeigen

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<module>
<general active="1">
<module_name>CL Contact Form</module_name>
<module_foldername>cl_contact_form</module_foldername>
<uuid></uuid>
<description>Default contact formular for CMS ConLite</description>
<author>Ortwin Pinke</author>
<copyright>Ortwin Pinke php-backoffice.de</copyright>
<license></license>
<mail>info@php-backoffice.de</mail>
<website>https://php-backoffice.de</website>
<version>1.0.0</version>
</general>
<requirements php="8.0">
<conlite minversion="3.0.0"/>
</requirements>
<!--
<dependencies>
<plugins>
<depend uuid="7071C44D-3B6F-5503-8C01-38B9A6A88E71">Smarty Wrapper</depend>
</plugins>
<module>
</module>
</dependencies>
<conlite>
</conlite>
-->
</module>

Datei anzeigen

@ -0,0 +1,60 @@
?><?php
/**
* Module cl-contact_form input
*
* @package module/cl_contact_form
* @author Ortwin Pinke <info@php-backoffice.de>
*
* based on w3concepts.form.v1 from Andreas Kummer (2004-08-20)
* modified and adapted to Contenido 4.8 under PHP 5.x by Murat Purc (2013-08-24)
*/
cInclude('frontend', 'includes/class.input.helper.php');
$uiConfigTable = new UI_Config_Table();
$htmlField = new cHTMLSelectElement("CMS_VAR[10]", 200);
$htmlField->autoFill([
'null' => mi18n("Bitte wählen"),
'mail' => mi18n("Mail (PHP)"),
'sendmail' => mi18n("Sendmail"),
'smtp' => mi18n("SMTP"),
'smtp_auth' => mi18n("SMTP mit oAuth")
]);
$htmlField->setDefault("CMS_VALUE[10]");
$uiConfigTable->setRowCell(0, mi18n("Versand mit:"));
$uiConfigTable->setRowCell(1, $htmlField->render());
$uiConfigTable->nextRow();
$htmlField = new cHTMLTextbox("CMS_VAR[0]", "CMS_VALUE[0]");
$htmlField->setWidth(30);
$uiConfigTable->setRowCell(0, mi18n("Zieladresse (alias@mydomain.com):"));
$uiConfigTable->setRowCell(1, $htmlField->render());
$uiConfigTable->nextRow();
$htmlField = new cHTMLTextbox("CMS_VAR[1]", "CMS_VALUE[1]");
$htmlField->setWidth(30);
$uiConfigTable->setRowCell(0, mi18n("Betreff:"));
$uiConfigTable->setRowCell(1, $htmlField->render());
$uiConfigTable->nextRow();
$htmlField = new cHTMLTextbox("CMS_VAR[2]", "CMS_VALUE[2]");
$htmlField->setWidth(30);
$uiConfigTable->setRowCell(0, mi18n("Antwortadresse (alias@mydomain.com):"));
$uiConfigTable->setRowCell(1, $htmlField->render());
$uiConfigTable->nextRow();
$htmlField = new cHTMLTextbox("CMS_VAR[3]", "CMS_VALUE[3]");
$htmlField->setWidth(30);
$uiConfigTable->setRowCell(0, mi18n("Emailname (z.B. Vorname Name):"));
$uiConfigTable->setRowCell(1, $htmlField->render());
$uiConfigTable->nextRow();
$htmlField = new cHTMLTextbox("CMS_VAR[4]", "CMS_VALUE[4]");
$htmlField->setWidth(8);
$uiConfigTable->setRowCell(0, mi18n("Hintergrundfarbe bei Fehlern (z.B. red):"));
$uiConfigTable->setRowCell(1, $htmlField->render());
$uiConfigTable->nextRow();
$uiConfigTable->render(true);
?><?php

Datei anzeigen

@ -1,15 +1,16 @@
<?php
global $sess;
/**
* Module cl-contactform output
* Module cl-contact_form output
*
* @package module/cl_contact_form
* @author Ortwin Pinke <info@php-backoffice.de>
*
* based on w3concepts.form.v1 from Andreas Kummer (2004-08-20)
* modified and adapted to Contenido 4.8 under PHP 5.x by Murat Purc (2013-08-24)
*/
use PHPMailer\PHPMailer\PHPMailer;
$sFrontEndPath = cRegistry::getClientConfig(cRegistry::getClientId())['path']['frontend'] . 'securimage' . DIRECTORY_SEPARATOR;
$captchaInstalled = false;
if (is_readable($sFrontEndPath)) {
@ -19,14 +20,15 @@ if (is_readable($sFrontEndPath)) {
$captchaInstalled = true;
}
class w3form
class FormGenerator
{
public $emailAdresses;
private array $email = ['adresses' => '', 'from' => ['name' => '', 'email' => ''], 'message' => '', 'subject' => ''];
private array $unraveled = [];
private array $form = ['form' => '', 'answer' => '', 'colorError' => ''];
public function __construct(private bool $captchaInstalled)
public function __construct(private bool $captchaInstalled, private cSession $cSession)
{
}
@ -36,18 +38,22 @@ class w3form
$this->unravel($this->suppress('sent'));
$this->generateEmailMessage();
$oMailer = new PHPMailer();
$oMailer->CharSet = "UTF-8";
$oMailer->AddAddress($this->email['adresses']);
$oMailer->From = $this->email['from']['email'];
$oMailer->FromName = $this->email['from']['name'];
$oMailer->Subject = $this->email['subject'];
$oMailer->Body = $this->email['message'];
$phpMailer = new \PHPMailer\PHPMailer\PHPMailer(true);
$phpMailer->isMail();
$phpMailer->isHTML(false);
$phpMailer->CharSet = "UTF-8";
$phpMailer->AddAddress($this->email['adresses']);
$phpMailer->setFrom($this->email['from']['email'], $this->email['from']['name']);
$phpMailer->Subject = $this->email['subject'];
$phpMailer->Body = $this->email['message'];
if ($oMailer->send()) {
return true;
try {
if ($phpMailer->send()) {
return true;
}
} catch (\PHPMailer\PHPMailer\Exception $e) {
echo $e->errorMessage();
}
return false;
}
@ -64,7 +70,7 @@ class w3form
private function add2Message($key, $value): void
{
if (strlen($key) > 25 or strlen($value) > 54) {
if (strlen($key) > 25 || strlen($value) > 54) {
$this->email['message'] .= "$key\n$value\n";
} else {
$this->email['message'] .= $key;
@ -75,18 +81,16 @@ class w3form
private function generateEmailMessage(): void
{
if ($this->unraveled)
foreach ($this->unraveled as $key => $value) {
$this->add2Message($key, $value);
}
foreach ($this->unraveled as $key => $value) {
$this->add2Message($key, $value);
}
}
private function suppress(): array
private function suppress(...$suppress): array
{
$fields = [];
$suppress = func_get_args();
foreach ($_POST as $key => $value) {
if (array_search($key, $suppress) === false)
if (!in_array($key, $suppress))
$fields[$key] = $value;
}
return $fields;
@ -131,8 +135,9 @@ class w3form
{
$fields = explode('###', $form);
$field = [];
$fieldsCount = count($fields);
for ($i = 1; $i < count($fields); $i = $i + 2) {
for ($i = 1; $i < $fieldsCount; $i += 2) {
$attribute = explode(';', trim($fields[$i]));
foreach ($attribute as $attribute) {
$nameValue = explode(':', trim($attribute));
@ -149,7 +154,8 @@ class w3form
public function formOutput($sent = false): void
{
echo '<div class="textItem secondItem"><form action="" method="POST" class="form-horizontal">';
$form_action = $this->cSession->url('front_content.php?idcat=' . cRegistry::getCategoryId() . '&idart=' . cRegistry::getArticleId());
echo '<form action="' . $form_action . '" method="post" class="form-horizontal">';
echo '<input type="hidden" name="sent" value="true" />';
$form = $this->form['form'];
$formData = $this->formInterpretation($form);
@ -162,45 +168,60 @@ class w3form
echo $item;
}
}
echo '</form></div>';
echo '</form>';
}
public function formField($attribute, $sent): void
{
$style = '';
$value = '';
$parameter = "name=\"{$attribute['name']}\"";
if ($sent && !$this->formFieldCorrect($attribute))
$style = "style=\"background-color:{$this->form['colorError']};\"";
switch ($attribute['type']) {
case 'select':
case 'password':
case 'text':
if (!empty($attribute['size']))
$parameter .= " size=\"{$attribute['size']}\"";
break;
$parameter = empty($attribute['id']) ? 'id="' . $attribute['name'] . '"' : 'id="' . $attribute['id'] . '"';
$parameter .= ' name="' . $attribute['name'] . '"';
if ($sent && !$this->formFieldCorrect($attribute)) {
$style = 'style="background-color: ' . $this->form['colorError'] . ';"';
}
if (!empty($attribute['class'])) {
$parameter .= ' class="' . $attribute['class'] . '"';
}
if (!empty($attribute['placeholder'])) {
$parameter .= ' placeholder="' . $attribute['placeholder'] . '"';
}
switch ($attribute['type']) {
case 'textarea':
case 'text':
if (!empty($attribute['size']))
$parameter .= " size=\"{$attribute['size']}\"";
if (!empty($attribute['value']))
if (!empty($attribute['size'])) {
$parameter .= ' size="' . $attribute['size'] . '"';
}
if (!empty($attribute['value'])) {
$value = $attribute['value'];
if (!empty($_POST["{$attribute['name']}"]))
}
if (!empty($_POST["{$attribute['name']}"])) {
$value = $_POST["{$attribute['name']}"];
}
break;
case 'select':
case 'password':
if (!empty($attribute['size'])) {
$parameter .= ' size="' . $attribute['size'] . '"';
}
break;
}
if (isset($attribute['required']) || isset($attribute['mandantory'])) {
$parameter .= ' required';
}
switch ($attribute['type']) {
case 'captcha':
if ($this->captchaInstalled) {
if ($sent) {
$captcha = @$_POST['ct_captcha'];
$capId = @$_POST['captcha_id'];
$captcha = @$_POST['lets_check'];
$securimage = new Securimage();
if (!$securimage->check($captcha)) {
@ -211,9 +232,10 @@ class w3form
}
// show captcha HTML using Securimage::getCaptchaHtml()
$options = [];
$options['input_name'] = 'ct_captcha'; // change name of input element for form post input_text
$options['show_audio_button'] = false;
$options['input_name'] = 'lets_check'; // change name of input element for form post input_text
$options['input_text'] = mi18n("Zeichen eingeben");
$options['input_required'] = false;
$options['input_required'] = true;
if (!empty($_SESSION['ctform']['captcha_error'])) {
// error html to show in captcha output
@ -223,13 +245,13 @@ class w3form
echo "<div id='captcha_container_1'>\n";
echo Securimage::getCaptchaHtml($options);
echo "\n</div>\n";
echo '<script src="securimage/securimage.js"></script>';
}
break;
case 'text':
echo "<input type=\"text\" $parameter value=\"$value\" $style />";
break;
case 'email':
case 'password':
echo "<input type=\"password\" $parameter value=\"$value\" $style />";
echo '<input type="'.$attribute['type'].'" '.$parameter.' value="'.$value.'" '.$style.' />';
break;
case 'textarea':
echo "<textarea name=\"{$attribute['name']}\" cols=\"";
@ -240,27 +262,22 @@ class w3form
break;
case 'select':
echo "<select $parameter $style>";
for ($i = 0; $i < (is_countable($attribute['option']) ? count($attribute['option']) : 0); $i++) {
$itemsCount = is_countable($attribute['option']) ? count($attribute['option']) : 0;
for ($i = 0; $i < (is_countable($attribute['option']) ? $itemsCount : 0); $i++) {
if (!empty($attribute['optionvalue'][$i])) {
if (!empty($_POST["{$attribute['name']}"]) && $_POST["{$attribute['name']}"] == $attribute['optionvalue'][$i]) {
echo "<option value=\"{$attribute['optionvalue'][$i]}\" selected=\"selected\">{$attribute['option'][$i]}</option>\n";
} elseif (empty($_POST["{$attribute['name']}"]) && !empty($attribute['optionvalue'][$i]) && $attribute['optionvalue'][$i] == $attribute['value']) {
echo "<option value=\"{$attribute['optionvalue'][$i]}\" selected=\"selected\">{$attribute['option'][$i]}</option>\n";
} else {
if (empty($_POST["{$attribute['name']}"]) && !empty($attribute['optionvalue'][$i]) && $attribute['optionvalue'][$i] == $attribute['value']) {
echo "<option value=\"{$attribute['optionvalue'][$i]}\" selected=\"selected\">{$attribute['option'][$i]}</option>\n";
} else {
echo "<option value=\"{$attribute['optionvalue'][$i]}\">{$attribute['option'][$i]}</option>\n";
}
echo "<option value=\"{$attribute['optionvalue'][$i]}\">{$attribute['option'][$i]}</option>\n";
}
} elseif (!empty($_POST["{$attribute['name']}"]) && $_POST["{$attribute['name']}"] == $attribute['option'][$i]) {
echo "<option selected=\"selected\">{$attribute['option'][$i]}</option>\n";
} elseif (empty($_POST["{$attribute['name']}"]) && $attribute['option'][$i] == $attribute['value']) {
echo "<option selected=\"selected\">{$attribute['option'][$i]}</option>\n";
} else {
if (!empty($_POST["{$attribute['name']}"]) && $_POST["{$attribute['name']}"] == $attribute['option'][$i]) {
echo "<option selected=\"selected\">{$attribute['option'][$i]}</option>\n";
} else {
if (empty($_POST["{$attribute['name']}"]) && $attribute['option'][$i] == $attribute['value']) {
echo "<option selected=\"selected\">{$attribute['option'][$i]}</option>\n";
} else {
echo "<option>{$attribute['option'][$i]}</option>\n";
}
}
echo "<option>{$attribute['option'][$i]}</option>\n";
}
}
echo "</select>";
@ -273,12 +290,10 @@ class w3form
} else {
echo "<label $style><input type=\"checkbox\" $parameter value=\"{$attribute['value']}\"/></label>";
}
} elseif (!empty($attribute['selected']) && $attribute['selected'] == 'true') {
echo "<input type=\"checkbox\" $parameter value=\"{$attribute['value']}\" checked=\"checked\"/>";
} else {
if (!empty($attribute['selected']) && $attribute['selected'] == 'true') {
echo "<input type=\"checkbox\" $parameter value=\"{$attribute['value']}\" checked=\"checked\"/>";
} else {
echo "<input type=\"checkbox\" $parameter value=\"{$attribute['value']}\"/>";
}
echo "<input type=\"checkbox\" $parameter value=\"{$attribute['value']}\"/>";
}
break;
case 'radio':
@ -288,12 +303,10 @@ class w3form
} else {
echo "<input type=\"radio\" $parameter value=\"{$attribute['value']}\" />";
}
} elseif (!empty($attribute['selected']) && $attribute['selected'] == 'true') {
echo "<input type=\"radio\" $parameter value=\"{$attribute['value']}\" checked=\"checked\"/>";
} else {
if (!empty($attribute['selected']) && $attribute['selected'] == 'true') {
echo "<input type=\"radio\" $parameter value=\"{$attribute['value']}\" checked=\"checked\"/>";
} else {
echo "<input type=\"radio\" $parameter value=\"{$attribute['value']}\"/>";
}
echo "<input type=\"radio\" $parameter value=\"{$attribute['value']}\"/>";
}
break;
}
@ -307,7 +320,7 @@ class w3form
switch ($field['type']) {
case 'captcha':
if ($this->captchaInstalled) {
$captcha = @$_POST['ct_captcha'];
$captcha = @$_POST['lets_check'];
$capId = @$_POST['captcha_id'];
$securimage = new Securimage();
if (!$securimage->check($captcha, $capId, true)) {
@ -328,7 +341,13 @@ class w3form
private function success(): void
{
if ($this->sendEmail()) {
echo $this->form['answer'];
$answer = trim($this->form['answer']);
if (mb_strlen($answer) > 0) {
echo $this->form['answer'];
} else {
echo '<span style="color:green;">' . mi18n("Form has been successfully send.") . '</span>';
}
} else {
echo '<span style="color:red;">' . mi18n("Es ist ein Fehler aufgetreten!<br>Bitte versuchen Sie es später noch einmal.") . '</span>';
}
@ -340,10 +359,8 @@ class w3form
$tmp_name = rtrim($field['name'], '[0]');
preg_match('/\[(\d*)\]/', $field['name'], $matches);
$bEmptyPost = false;
$bIsPostArray = false;
$sPostFieldValue = $_POST[$tmp_name];
if (is_array($_POST[$tmp_name])) {
$bIsPostArray == true;
$sPostFieldValue = $_POST[$tmp_name][$matches[1]];
if (empty($_POST[$tmp_name][$matches[1]])) {
$bEmptyPost = true;
@ -416,10 +433,7 @@ class w3form
// längenbereich bei allen typen prüfen
if (!empty($field['minlength']) && strlen($sPostFieldValue) < $field['minlength'])
return false;
if (!empty($field['maxlength']) && strlen($sPostFieldValue) > $field['maxlength'])
return false;
return true;
return !(!empty($field['maxlength']) && strlen($sPostFieldValue) > $field['maxlength']);
}
public function process(): void
@ -435,20 +449,23 @@ class w3form
}
if (isset($edit) && $edit) {
echo "<h1>" . mi18n("Formularkonfiguration") . "</h1>";
echo "<p>" . mi18n("Hier ist das Formular sowie der Text einzugeben, der zusammen mit dem Formular ausgegeben werden soll:") . "</p>";
echo "CMS_HTML[0]";
echo "<p>" . mi18n("Hier ist die Ausgabe einzugeben, die erscheint, wenn das Formular erfolgreich prozessiert worden ist:") . "</p>";
echo "CMS_HTML[1]";
if (cRegistry::isBackendEditMode()) {
echo "<hr>";
echo "<h3>" . mi18n("Formularkonfiguration") . "</h3>";
echo "<h4>" . mi18n("Hier ist das Formular sowie der Text einzugeben, der zusammen mit dem Formular ausgegeben werden soll:") . "</h4>";
echo "CMS_HTML[100]";
echo "<h4>" . mi18n("Hier ist die Ausgabe einzugeben, die erscheint, wenn das Formular erfolgreich verschickt wurde:") . "</h4>";
echo "CMS_HTML[101]";
echo "<hr>";
} else {
$form = new w3form($captchaInstalled);
$form = new FormGenerator($captchaInstalled, $sess);
$form->addEmailAdress("CMS_VALUE[0]");
$form->setEmailSubject("CMS_VALUE[1]");
$form->setEmailFrom("CMS_VALUE[2]", "CMS_VALUE[3]");
$form->setBackgroundError("CMS_VALUE[4]");
$form->setForm("CMS_HTML[0]");
$form->setAnswer("CMS_HTML[1]");
$form->setForm("CMS_HTML[100]");
$form->setAnswer("CMS_HTML[101]");
$form->process();
}
?>
?>

Datei anzeigen

@ -1,40 +0,0 @@
?><?php
/**
* Module cl-contactform input
*
* @author Ortwin Pinke <info@php-backoffice.de>
*
* based on w3concepts.form.v1 from Andreas Kummer (2004-08-20)
* modified and adapted to Contenido 4.8 under PHP 5.x by Murat Purc (2013-08-24)
*/
cInclude('frontend', 'includes/class.input.helper.php');
$oCfgTable = new UI_Config_Table();
$oField = new cHTMLTextbox("CMS_VAR[0]", "CMS_VALUE[0]");
$oField->setWidth(30);
$oCfgTable->setCell(0, 0, mi18n("Zieladresse (alias@mydomain.com):"));
$oCfgTable->setCell(0, 1, $oField->render());
$oField = new cHTMLTextbox("CMS_VAR[1]", "CMS_VALUE[1]");
$oField->setWidth(30);
$oCfgTable->setCell(1, 0, mi18n("Betreff:"));
$oCfgTable->setCell(1, 1, $oField->render());
$oField = new cHTMLTextbox("CMS_VAR[2]", "CMS_VALUE[2]");
$oField->setWidth(30);
$oCfgTable->setCell(2, 0, mi18n("Antwortadresse (alias@mydomain.com):"));
$oCfgTable->setCell(2, 1, $oField->render());
$oField = new cHTMLTextbox("CMS_VAR[3]", "CMS_VALUE[3]");
$oField->setWidth(30);
$oCfgTable->setCell(3, 0, mi18n("Emailname (z.B. Vorname Name):"));
$oCfgTable->setCell(3, 1, $oField->render());
$oField = new cHTMLTextbox("CMS_VAR[4]", "CMS_VALUE[4]");
$oField->setWidth(8);
$oCfgTable->setCell(4, 0, mi18n("Hintergrundfarbe bei Fehlern (z.B. red):"));
$oCfgTable->setCell(4, 1, $oField->render());
$oCfgTable->render(true);
?><?php

Datei anzeigen

@ -1,610 +0,0 @@
<?php
/**
* Project:
* Contenido Content Management System
*
* Description:
* Various derived HTML class elements especially useful
* in the input area of modules
* Simple table generation class especially useful to generate
* backend configuration table. May be used also in Frontend,
* but note the globally used variables ($cfg)
*
* Usage: Store file in client/includes folder (generate the
* includes folder, if not available). Include the file
* in your modules using
* cInclude("frontend", "includes/class.input.helper.php");
*
* @package Frontend
* @subpackage InputHelpers
* @version 2.1 (formerly known as functions.input.helper.php)
* @author Björn Behrens (HerrB), http://www.btech.de
* @copyright four for business AG <www.4fb.de>
* @license http://www.contenido.org/license/LIZENZ.txt
* @link http://www.4fb.de
* @link http://www.contenido.org
*
* $Id$:
*/
if (!defined('CON_FRAMEWORK')) {
die('Illegal call');
}
// Select box with additional functions for category and article selection
class cHTMLInputSelectElement extends cHTMLSelectElement {
/**
* Constructor. Creates an HTML select field (aka "DropDown").
*
* @param string $sName Name of the element
* @param int $iWidth Width of the select element
* @param string $sID ID of the element
* @param string $bDisabled Item disabled flag (non-empty to set disabled)
* @param int $iTabIndex Tab index for form elements
* @param string $sAccesskey Key to access the field
*
* @return none
* */
function __construct($sName, $iWidth = "", $sID = "", $bDisabled = false, $iTabIndex = null, $sAccessKey = "") {
cHTMLSelectElement :: __construct($sName, $iWidth, $sID, $bDisabled, $iTabIndex, $sAccessKey);
}
/**
* Function addArticles. Adds articles to select box values.
*
* @param int $iIDCat idcat of the category to be listed
* @param bool $bColored Add color information to option elements
* @param bool $bArtOnline If true, only online articles will be added
* @param string $sSpaces Just some "&nbsp;" to show data hierarchically (used in conjunction with addCategories)
*
* @return int Number of items added
* */
function addArticles($iIDCat, $bColored = false, $bArtOnline = true, $sSpaces = "") {
global $cfg, $lang;
$oDB = new DB_Contenido;
if (is_numeric($iIDCat) && $iIDCat > 0) {
$sSQL = "SELECT tblArtLang.title AS title, tblArtLang.idartlang AS idartlang, tblCatArt.idcat AS idcat, ";
$sSQL .= "tblCatArt.idcatart AS idcatart, tblCatArt.is_start AS isstart, tblArtLang.online AS online, ";
$sSQL .= "tblCatLang.startidartlang as idstartartlang ";
$sSQL .= "FROM " . $cfg["tab"]["art_lang"] . " AS tblArtLang, " . $cfg["tab"]["cat_art"] . " AS tblCatArt, ";
$sSQL .= $cfg["tab"]["cat_lang"] . " AS tblCatLang ";
$sSQL .= "WHERE tblCatArt.idcat = '" . Contenido_Security::toInteger($iIDCat) . "' AND tblCatLang.idcat = tblCatArt.idcat AND tblCatLang.idlang = tblArtLang.idlang AND ";
if ($bArtOnline) {
$sSQL .= "tblArtLang.online = '1' AND ";
}
$sSQL .= "tblArtLang.idart = tblCatArt.idart AND tblArtLang.idlang = '" . Contenido_Security::escapeDB($lang, $oDB) . "' ";
if ($cfg["is_start_compatible"] == true) {
$sSQL .= "ORDER BY tblCatArt.is_start DESC, tblArtLang.title"; // Getting start article as first article
} else {
$sSQL .= "ORDER BY tblArtLang.title";
}
$oDB->query($sSQL);
$iCount = $oDB->num_rows();
if ($iCount == 0) {
return 0;
} else {
$iCounter = count($this->_options);
while ($oDB->next_record()) {
// Generate new option element
$oOption = new cHTMLOptionElement($sSpaces . "&nbsp;&nbsp;&nbsp;" . substr(urldecode($oDB->f("title")), 0, 32), $oDB->f("idcatart"));
if ($bColored) {
$bIsStartArticle = false;
if ($cfg["is_start_compatible"] == true && $oDB->f("isstart") == 1) {
// Compatible mode and "start article" flag is set
$bIsStartArticle = true;
} else if ($cfg["is_start_compatible"] != true && $oDB->f("idstartartlang") == $oDB->f("idartlang")) {
// No compatible mode and current article is start article (idstartartlang is the same for all records within a category)
$bIsStartArticle = true;
}
if ($bIsStartArticle) {
if ($oDB->f("online") == 0) {
// Start article, but offline -> red
$oOption->setStyle("color: #ff0000;");
} else {
// Start article -> blue
$oOption->setStyle("color: #0000ff;");
}
} else if ($oDB->f("online") == 0) {
// Offline article -> grey
$oOption->setStyle("color: #666666;");
}
}
// Add option element to the list
$this->addOptionElement($iCounter, $oOption);
$iCounter++;
}
return $iCount;
}
} else {
return 0;
}
}
/**
* Function addCategories. Adds category elements (optionally including articles) to select box values.
* Note: Using "with articles" adds the articles also - but the categories will get a negative value!
* There is no way to distinguish between a category id and an article id...
*
* @param int $iMaxLevel Max. level shown (to be exact: except this level)
* @param bool $bColored Add color information to option elements
* @param bool $bCatVisible If true, only add idcat as value, if cat is visible
* @param bool $bCatPublic If true, only add idcat as value, if cat is public
* @param bool $bWithArt Add also articles per category
* @param bool $bArtOnline If true, show only online articles
*
* @return int Number of items added
* */
function addCategories($iMaxLevel = 0, $bColored = false, $bCatVisible = true, $bCatPublic = true, $bWithArt = false, $bArtOnline = true) {
global $cfg, $client, $lang;
$oDB = new DB_Contenido;
$sSQL = "SELECT tblCat.idcat AS idcat, tblCatLang.name AS name, ";
$sSQL .= "tblCatLang.visible AS visible, tblCatLang.public AS public, tblCatTree.level AS level ";
$sSQL .= "FROM " . $cfg["tab"]["cat"] . " AS tblCat, " . $cfg["tab"]["cat_lang"] . " AS tblCatLang, ";
$sSQL .= $cfg["tab"]["cat_tree"] . " AS tblCatTree ";
$sSQL .= "WHERE tblCat.idclient = '" . Contenido_Security::escapeDB($client, $oDB) . "' AND tblCatLang.idlang = '" . Contenido_Security::escapeDB($lang, $oDB) . "' AND ";
$sSQL .= "tblCatLang.idcat = tblCat.idcat AND tblCatTree.idcat = tblCat.idcat ";
if ($iMaxLevel > 0) {
$sSQL .= "AND tblCatTree.level < '" . Contenido_Security::escapeDB($iMaxLevel, $oDB) . "' ";
}
$sSQL .= "ORDER BY tblCatTree.idtree";
$oDB->query($sSQL);
$iCount = $oDB->num_rows();
if ($iCount == 0) {
return false;
} else {
$iCounter = count($this->_options);
while ($oDB->next_record()) {
$sSpaces = "";
$sStyle = "";
$iID = $oDB->f("idcat");
for ($i = 0; $i < $oDB->f("level"); $i++) {
$sSpaces .= "&nbsp;&nbsp;&nbsp;";
}
// Generate new option element
if (($bCatVisible && $oDB->f("visible") == 0) || ($bCatPublic && $oDB->f("public") == 0)) {
// If category has to be visible or public and it isn't, don't add value
$sValue = "";
} else if ($bWithArt) {
// If article will be added, set negative idcat as value
$sValue = "-" . $iID;
} else {
// Show only categories - and everything is fine...
$sValue = $iID;
}
$oOption = new cHTMLOptionElement($sSpaces . ">&nbsp;" . urldecode($oDB->f("name")), $sValue);
// Coloring option element, restricted shows grey color
$oOption->setStyle("background-color: #EFEFEF");
if ($bColored && ($oDB->f("visible") == 0 || $oDB->f("public") == 0)) {
$oOption->setStyle("color: #666666;");
}
// Add option element to the list
$this->addOptionElement($iCounter, $oOption);
if ($bWithArt) {
$iArticles = $this->addArticles($iID, $bColored, $bArtOnline, $sSpaces);
$iCount += $iArticles;
}
$iCounter = count($this->_options);
}
}
return $iCount;
}
/**
* Function addTypesFromArt. Adds types and type ids which are available for the specified article
*
* @param int $iIDCatArt Article id
* @param string $sTypeRange Komma separated list of Contenido type ids which may be in the resulting list (e.g. '1','17','28')
*
* @return int Number of items added
* */
function addTypesFromArt($iIDCatArt, $sTypeRange = "") {
global $cfg, $lang;
$oDB = new DB_Contenido;
if (is_numeric($iIDCatArt) && $iIDCatArt > 0) {
$sSQL = "SELECT tblContent.typeid AS typeid, tblContent.idtype AS idtype, tblType.type AS type, tblType.description AS description, ";
$sSQL .= "tblContent.value AS value ";
$sSQL .= "FROM " . $cfg["tab"]["content"] . " AS tblContent, " . $cfg["tab"]["art_lang"] . " AS tblArtLang, ";
$sSQL .= $cfg["tab"]["cat_art"] . " AS tblCatArt, " . $cfg["tab"]["type"] . " AS tblType ";
$sSQL .= "WHERE tblContent.idtype = tblType.idtype AND tblContent.idartlang = tblArtLang.idartlang AND ";
$sSQL .= "tblArtLang.idart = tblCatArt.idart AND tblArtLang.idlang = '" . Contenido_Security::escapeDB($lang, $oDB) . "' AND tblCatArt.idcatart = '" . Contenido_Security::toInteger($iIDCatArt) . "' ";
if ($sTypeRange != "") {
$sSQL .= "AND tblContent.idtype IN (" . Contenido_Security::escapeDB($sTypeRange, $oDB) . ") ";
}
$sql .= "ORDER BY tblContent.idtype, tblContent.typeid";
$oDB->query($sSQL);
$iCount = $oDB->num_rows();
if ($iCount == 0) {
return false;
} else {
while ($oDB->next_record()) {
$sTypeIdentifier = "tblData.idtype = '" . $oDB->f('idtype') . "' AND tblData.typeid = '" . $oDB->f('typeid') . "'";
// Generate new option element
$oOption = new cHTMLOptionElement($oDB->f('type') . "[" . $oDB->f('typeid') . "]: " . substr(strip_tags(urldecode($oDB->f("value"))), 0, 50), $sTypeIdentifier);
// Add option element to the list
$this->addOptionElement($sTypeIdentifier, $oOption);
}
return $iCount;
}
} else {
return false;
}
}
public function addFiles($sPath) {
$iCount = 0;
$aFiles = cDirHandler::read($sPath);
asort($aFiles);
$iCounter = count($this->_options);
foreach ($aFiles as $sValue) {
$oOption = new cHTMLOptionElement($sValue, $sValue);
$this->addOptionElement($iCounter, $oOption);
$iCounter++;
}
return count($aFiles);
}
}
class UI_Config_Table {
var $_sTplCellCode;
var $_sTplTableFile;
var $_sWidth;
var $_sBorder;
var $_sBorderColor;
var $_bSolidBorder;
var $_sPadding;
var $_aCells;
var $_aCellAlignment;
var $_aCellVAlignment;
var $_aCellColSpan;
var $_aCellClass;
var $_aRowBgColor;
var $_aRowExtra;
var $_bAddMultiSelJS;
var $_sColorLight;
var $_sColorDark;
/**
*
* @var type
*/
protected $_iRowCnt = 0;
function __construct() {
$cfg = cRegistry::getConfig();
$this->_sPadding = 2;
$this->_sBorder = 0;
$this->_sBorderColor = cRegistry::getConfigValue('color', 'table_border');
$this->_sTplCellCode = '<td align="{ALIGN}" valign="{VALIGN}" class="{CLASS}" colspan="{COLSPAN}" style="{EXTRA}white-space:nowrap;" nowrap="nowrap">' . "\n"
. '{CONTENT}' . "\n"
. '</td>' . "\n";
$this->_sTplTableFile = $cfg['path']['contenido'] . $cfg['path']['templates'] . $cfg['templates']['generic_list'];
$this->_sColorLight = cRegistry::getConfigValue('color', 'table_light');
$this->_sColorDark = cRegistry::getConfigValue('color', 'table_dark');
}
function setCellTemplate($sCode) {
$this->_sTplCellCode = $sCode;
}
function setTableTemplateFile($sPath) {
$this->_sTplTableFile = $sPath;
}
function setLightColor($sColor) {
$this->_sColorLight = $sColor;
}
function setDarkColor($sColor) {
$this->_sColorDark = $sColor;
}
function setAddMultiSelJS($bEnabled = true) {
$this->_bAddMultiSelJS = (bool) $bEnabled;
}
function setWidth($sWidth) {
$this->_sWidth = $sWidth;
}
function setPadding($sPadding) {
$this->_sPadding = $sPadding;
}
function setBorder($sBorder) {
$this->_sBorder = $sBorder;
}
function setBorderColor($sBorderColor) {
$this->_sBorderColor = $sBorderColor;
}
function setSolidBorder($bSolidBorder = true) {
$this->_bSolidBorder = (bool) $bSolidBorder;
}
function setCell($sRow, $sCell, $sContent) {
$this->_aCells[$sRow][$sCell] = $sContent;
$this->_aCellAlignment[$sRow][$sCell] = "";
}
function setCellAlignment($sRow, $sCell, $sAlignment) {
$this->_aCellAlignment[$sRow][$sCell] = $sAlignment;
}
function setCellVAlignment($sRow, $sCell, $sAlignment) {
$this->_aCellVAlignment[$sRow][$sCell] = $sAlignment;
}
function setCellColspan($sRow, $sCell, $iColSpan) {
$this->_aCellColSpan[$sRow][$sCell] = $iColSpan;
}
function setCellClass($sRow, $sCell, $sClass) {
$this->_aCellClass[$sRow][$sCell] = $sClass;
}
function setRowBgColor($sRow, $sColor) {
$this->_aRowBgColor[$sRow] = $sColor;
}
function setRowExtra($sRow, $sExtra) {
$this->_aRowExtra[$sRow] = $sExtra;
}
function _addMultiSelJS() {
// Trick: To save multiple selections in <select>-Element, add some JS which saves the
// selection, comma separated in a hidden input field on change.
// Try ... catch prevents error messages, if function is added more than once
// if (!fncUpdateSel) in JS has not worked...
$sSkript = ' <script type="text/javascript"><!--' . "\n" .
' try {' . "\n" .
' function fncUpdateSel(sSelectBox, sStorage)' . "\n" .
' {' . "\n" .
' var sSelection = "";' . "\n" .
' var oSelectBox = document.getElementsByName(sSelectBox)[0];' . "\n" .
' var oStorage = document.getElementsByName(sStorage)[0];' . "\n" .
' ' . "\n" .
' if (oSelectBox && oStorage)' . "\n" .
' {' . "\n" .
' for (i = 0; i < oSelectBox.length; i++)' . "\n" .
' {' . "\n" .
' if(oSelectBox.options[i].selected == true)' . "\n" .
' {' . "\n" .
' if (sSelection != "")' . "\n" .
' sSelection = sSelection + ",";' . "\n" .
' sSelection = sSelection + oSelectBox.options[i].value;' . "\n" .
' }' . "\n" .
' }' . "\n" .
' oStorage.value = sSelection;' . "\n" .
' }' . "\n" .
' }' . "\n" .
' } catch (e) { }' . "\n" .
' //--></script>' . "\n";
return $sSkript;
}
/**
* increase row counter
*/
public function nextRow() {
$this->_iRowCnt++;
}
/**
* get current row count
*
* @return int row count
*/
public function getRowCount() : int {
return $this->_iRowCnt;
}
public function setRowCell(int $iCell, $mContent) {
$this->setCell($this->_iRowCnt, $iCell, $mContent);
}
public function setRowBorder(string $sWhich = 'bottom') {
$sStyle = '';
switch ($sWhich) {
case 'bottom':
$this->setRowExtra($this->_iRowCnt, 'border-bottom: 1px solid silver;');
break;
}
}
public function render($bPrint = false) {
$oTable = new Template();
$oTable->reset();
$oTable->set('s', 'CELLPADDING', $this->_sPadding);
$oTable->set('s', 'BORDER', $this->_sBorder);
$oTable->set('s', 'BORDERCOLOR', $this->_sBorderColor);
$iColCount = 0;
$bDark = false;
$sBgColor = "";
$bMultiSelJSAdded = false;
if (is_array($this->_aCells)) {
foreach ($this->_aCells as $sRow => $aCells) {
$iColCount++;
//$bDark = !$bDark;
$sLine = "";
$iCount = 0;
foreach ($aCells as $sCell => $sData) {
$sData = $this->_processContentData($sData);
$iCount++;
$sTplCell = $this->_sTplCellCode;
if ($this->_bSolidBorder) {
if ($iCount < count($aCells)) {
if ($iColCount < count($this->_aCells)) {
$sTplCell = str_replace('{EXTRA}', 'border: 0px; border-right: 1px; border-bottom: 1px; border-color: ' . $this->_sBorderColor . '; border-style: solid;', $sTplCell);
} else {
$sTplCell = str_replace('{EXTRA}', 'border: 0px; border-right: 1px; border-color: ' . $this->_sBorderColor . '; border-style: solid;', $sTplCell);
}
} else if ($iColCount < count($this->_aCells)) {
$sTplCell = str_replace('{EXTRA}', 'border: 0px; border-bottom: 1px; border-color: ' . $this->_sBorderColor . '; border-style: solid;', $sTplCell);
} else {
$sTplCell = str_replace('{EXTRA}', '', $sTplCell);
}
}
if ($this->_aCellAlignment[$sRow][$sCell] != "") {
$sTplCell = str_replace('{ALIGN}', $this->_aCellAlignment[$sRow][$sCell], $sTplCell);
} else {
$sTplCell = str_replace('{ALIGN}', 'left', $sTplCell);
}
if ($this->_aCellVAlignment[$sRow][$sCell] != "") {
$sTplCell = str_replace('{VALIGN}', $this->_aCellVAlignment[$sRow][$sCell], $sTplCell);
} else {
$sTplCell = str_replace('{VALIGN}', 'top', $sTplCell);
}
if ($this->_aCellColSpan[$sRow][$sCell] != "") {
$sTplCell = str_replace('{COLSPAN}', $this->_aCellColSpan[$sRow][$sCell], $sTplCell);
} else {
$sTplCell = str_replace('{COLSPAN}', '1', $sTplCell);
}
if ($this->_aCellClass[$sRow][$sCell] != "") {
$sTplCell = str_replace('{CLASS}', $this->_aCellClass[$sRow][$sCell], $sTplCell);
} else {
$sTplCell = str_replace('{CLASS}', 'text', $sTplCell);
}
// Multi selection javascript
if ($this->_bAddMultiSelJS) {
$sData = $this->_addMultiSelJS() . $sData;
$this->_bAddMultiSelJS = false;
}
$sTplCell = str_replace('{CONTENT}', $sData, $sTplCell);
$sLine .= $sTplCell;
}
// Row
$oTable->set('d', 'ROWS', $sLine);
if ($this->_aRowBgColor[$sRow] != "") {
$sBgColor = $this->_aRowBgColor[$sRow];
} else if ($sBgColor == $this->_sColorLight) {
$sBgColor = $this->_sColorDark;
} else {
$sBgColor = $this->_sColorLight;
}
$oTable->set('d', 'BGCOLOR', $sBgColor);
if ($this->_aRowExtra[$sRow] != "") {
$oTable->set('d', 'EXTRA', $this->_aRowExtra[$sRow]);
} else {
$oTable->set('d', 'EXTRA', '');
}
$oTable->next();
}
}
if ($this->_sWidth) {
// Table: Width
$oTable->set('s', 'EXTRA', 'width: ' . $this->_sWidth . ';');
} else {
$oTable->set('s', 'EXTRA', '');
}
$sRendered = $oTable->generate($this->_sTplTableFile, true, false);
if ($bPrint == true) {
echo $sRendered;
} else {
return $sRendered;
}
}
/**
* returns different types of content data as string
* you can use
* - string
* - object, needs to have a render method
* - array of objects and/or strings
*
* @author Ortwin Pinke
* @since 2.3.0
*
*
* @param mixed $mData
* @return string
*/
protected function _processContentData($mData): string {
if (is_string($mData)) {
return $mData;
}
$sData = '';
if (is_array($mData) && count($mData) > 0) {
foreach ($mData as $mElement) {
if (is_string($mElement)) {
$sData .= $mElement;
continue;
}
$sData .= $this->_renderObject($mElement);
}
} else {
$sData = $this->_renderObject($mData);
}
return $sData;
}
/**
* Renders an object using its render method
*
* @author Ortwin Pinke
* @since 2.3.0
*
* @param type $oObject
* @return string rendered string from object | empty string
*/
protected function _renderObject($oObject): string {
$sReturn = '';
if (is_object($oObject) && method_exists($oObject, 'render')) {
$sReturn = $oObject->render();
}
return $sReturn;
}
}

Datei anzeigen

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<modulepackage><package_guid/>
<package_data/>
<module><name>CL Contactform</name>
<module><name>CL Contact Form</name>
<description>&lt;Ihre Modulbeschreibung&gt;
Autor:
@ -9,8 +9,9 @@ Version:</description>
<type>Content</type>
<input>?&gt;&lt;?php
/**
* Module cl-contactform input
* Module cl-contact_form input
*
* @package module/cl_contact_form
* @author Ortwin Pinke &lt;info@php-backoffice.de&gt;
*
* based on w3concepts.form.v1 from Andreas Kummer (2004-08-20)
@ -18,47 +19,67 @@ Version:</description>
*/
cInclude(&#039;frontend&#039;, &#039;includes/class.input.helper.php&#039;);
$oCfgTable = new UI_Config_Table();
$uiConfigTable = new UI_Config_Table();
$oField = new cHTMLTextbox(&quot;CMS_VAR[0]&quot;, &quot;CMS_VALUE[0]&quot;);
$oField-&gt;setWidth(30);
$oCfgTable-&gt;setCell(0, 0, mi18n(&quot;Zieladresse (alias@mydomain.com):&quot;));
$oCfgTable-&gt;setCell(0, 1, $oField-&gt;render());
$htmlField = new cHTMLSelectElement(&quot;CMS_VAR[10]&quot;, 200);
$htmlField-&gt;autoFill([
&#039;null&#039; =&gt; mi18n(&quot;Bitte wählen&quot;),
&#039;mail&#039; =&gt; mi18n(&quot;Mail (PHP)&quot;),
&#039;sendmail&#039; =&gt; mi18n(&quot;Sendmail&quot;),
&#039;smtp&#039; =&gt; mi18n(&quot;SMTP&quot;),
&#039;smtp_auth&#039; =&gt; mi18n(&quot;SMTP mit oAuth&quot;)
]);
$htmlField-&gt;setDefault(&quot;CMS_VALUE[10]&quot;);
$uiConfigTable-&gt;setRowCell(0, mi18n(&quot;Versand mit:&quot;));
$uiConfigTable-&gt;setRowCell(1, $htmlField-&gt;render());
$uiConfigTable-&gt;nextRow();
$oField = new cHTMLTextbox(&quot;CMS_VAR[1]&quot;, &quot;CMS_VALUE[1]&quot;);
$oField-&gt;setWidth(30);
$oCfgTable-&gt;setCell(1, 0, mi18n(&quot;Betreff:&quot;));
$oCfgTable-&gt;setCell(1, 1, $oField-&gt;render());
$htmlField = new cHTMLTextbox(&quot;CMS_VAR[0]&quot;, &quot;CMS_VALUE[0]&quot;);
$htmlField-&gt;setWidth(30);
$uiConfigTable-&gt;setRowCell(0, mi18n(&quot;Zieladresse (alias@mydomain.com):&quot;));
$uiConfigTable-&gt;setRowCell(1, $htmlField-&gt;render());
$uiConfigTable-&gt;nextRow();
$oField = new cHTMLTextbox(&quot;CMS_VAR[2]&quot;, &quot;CMS_VALUE[2]&quot;);
$oField-&gt;setWidth(30);
$oCfgTable-&gt;setCell(2, 0, mi18n(&quot;Antwortadresse (alias@mydomain.com):&quot;));
$oCfgTable-&gt;setCell(2, 1, $oField-&gt;render());
$htmlField = new cHTMLTextbox(&quot;CMS_VAR[1]&quot;, &quot;CMS_VALUE[1]&quot;);
$htmlField-&gt;setWidth(30);
$uiConfigTable-&gt;setRowCell(0, mi18n(&quot;Betreff:&quot;));
$uiConfigTable-&gt;setRowCell(1, $htmlField-&gt;render());
$uiConfigTable-&gt;nextRow();
$oField = new cHTMLTextbox(&quot;CMS_VAR[3]&quot;, &quot;CMS_VALUE[3]&quot;);
$oField-&gt;setWidth(30);
$oCfgTable-&gt;setCell(3, 0, mi18n(&quot;Emailname (z.B. Vorname Name):&quot;));
$oCfgTable-&gt;setCell(3, 1, $oField-&gt;render());
$htmlField = new cHTMLTextbox(&quot;CMS_VAR[2]&quot;, &quot;CMS_VALUE[2]&quot;);
$htmlField-&gt;setWidth(30);
$uiConfigTable-&gt;setRowCell(0, mi18n(&quot;Antwortadresse (alias@mydomain.com):&quot;));
$uiConfigTable-&gt;setRowCell(1, $htmlField-&gt;render());
$uiConfigTable-&gt;nextRow();
$oField = new cHTMLTextbox(&quot;CMS_VAR[4]&quot;, &quot;CMS_VALUE[4]&quot;);
$oField-&gt;setWidth(8);
$oCfgTable-&gt;setCell(4, 0, mi18n(&quot;Hintergrundfarbe bei Fehlern (z.B. red):&quot;));
$oCfgTable-&gt;setCell(4, 1, $oField-&gt;render());
$oCfgTable-&gt;render(true);
$htmlField = new cHTMLTextbox(&quot;CMS_VAR[3]&quot;, &quot;CMS_VALUE[3]&quot;);
$htmlField-&gt;setWidth(30);
$uiConfigTable-&gt;setRowCell(0, mi18n(&quot;Emailname (z.B. Vorname Name):&quot;));
$uiConfigTable-&gt;setRowCell(1, $htmlField-&gt;render());
$uiConfigTable-&gt;nextRow();
$htmlField = new cHTMLTextbox(&quot;CMS_VAR[4]&quot;, &quot;CMS_VALUE[4]&quot;);
$htmlField-&gt;setWidth(8);
$uiConfigTable-&gt;setRowCell(0, mi18n(&quot;Hintergrundfarbe bei Fehlern (z.B. red):&quot;));
$uiConfigTable-&gt;setRowCell(1, $htmlField-&gt;render());
$uiConfigTable-&gt;nextRow();
$uiConfigTable-&gt;render(true);
?&gt;&lt;?php</input>
<output>&lt;?php
global $sess;
/**
* Module cl-contactform output
* Module cl-contact_form output
*
* @package module/cl_contact_form
* @author Ortwin Pinke &lt;info@php-backoffice.de&gt;
*
* based on w3concepts.form.v1 from Andreas Kummer (2004-08-20)
* modified and adapted to Contenido 4.8 under PHP 5.x by Murat Purc (2013-08-24)
*/
use PHPMailer\PHPMailer\PHPMailer;
$sFrontEndPath = cRegistry::getClientConfig(cRegistry::getClientId())[&#039;path&#039;][&#039;frontend&#039;] . &#039;securimage&#039; . DIRECTORY_SEPARATOR;
$captchaInstalled = false;
if (is_readable($sFrontEndPath)) {
@ -68,14 +89,15 @@ if (is_readable($sFrontEndPath)) {
$captchaInstalled = true;
}
class w3form
class FormGenerator
{
public $emailAdresses;
private array $email = [&#039;adresses&#039; =&gt; &#039;&#039;, &#039;from&#039; =&gt; [&#039;name&#039; =&gt; &#039;&#039;, &#039;email&#039; =&gt; &#039;&#039;], &#039;message&#039; =&gt; &#039;&#039;, &#039;subject&#039; =&gt; &#039;&#039;];
private array $unraveled = [];
private array $form = [&#039;form&#039; =&gt; &#039;&#039;, &#039;answer&#039; =&gt; &#039;&#039;, &#039;colorError&#039; =&gt; &#039;&#039;];
public function __construct(private bool $captchaInstalled)
public function __construct(private bool $captchaInstalled, private cSession $cSession)
{
}
@ -85,18 +107,22 @@ class w3form
$this-&gt;unravel($this-&gt;suppress(&#039;sent&#039;));
$this-&gt;generateEmailMessage();
$oMailer = new PHPMailer();
$oMailer-&gt;CharSet = &quot;UTF-8&quot;;
$oMailer-&gt;AddAddress($this-&gt;email[&#039;adresses&#039;]);
$oMailer-&gt;From = $this-&gt;email[&#039;from&#039;][&#039;email&#039;];
$oMailer-&gt;FromName = $this-&gt;email[&#039;from&#039;][&#039;name&#039;];
$oMailer-&gt;Subject = $this-&gt;email[&#039;subject&#039;];
$oMailer-&gt;Body = $this-&gt;email[&#039;message&#039;];
$phpMailer = new \PHPMailer\PHPMailer\PHPMailer(true);
$phpMailer-&gt;isMail();
$phpMailer-&gt;isHTML(false);
$phpMailer-&gt;CharSet = &quot;UTF-8&quot;;
$phpMailer-&gt;AddAddress($this-&gt;email[&#039;adresses&#039;]);
$phpMailer-&gt;setFrom($this-&gt;email[&#039;from&#039;][&#039;email&#039;], $this-&gt;email[&#039;from&#039;][&#039;name&#039;]);
$phpMailer-&gt;Subject = $this-&gt;email[&#039;subject&#039;];
$phpMailer-&gt;Body = $this-&gt;email[&#039;message&#039;];
if ($oMailer-&gt;send()) {
return true;
try {
if ($phpMailer-&gt;send()) {
return true;
}
} catch (\PHPMailer\PHPMailer\Exception $e) {
echo $e-&gt;errorMessage();
}
return false;
}
@ -113,7 +139,7 @@ class w3form
private function add2Message($key, $value): void
{
if (strlen($key) &gt; 25 or strlen($value) &gt; 54) {
if (strlen($key) &gt; 25 || strlen($value) &gt; 54) {
$this-&gt;email[&#039;message&#039;] .= &quot;$key\n$value\n&quot;;
} else {
$this-&gt;email[&#039;message&#039;] .= $key;
@ -124,18 +150,16 @@ class w3form
private function generateEmailMessage(): void
{
if ($this-&gt;unraveled)
foreach ($this-&gt;unraveled as $key =&gt; $value) {
$this-&gt;add2Message($key, $value);
}
foreach ($this-&gt;unraveled as $key =&gt; $value) {
$this-&gt;add2Message($key, $value);
}
}
private function suppress(): array
private function suppress(...$suppress): array
{
$fields = [];
$suppress = func_get_args();
foreach ($_POST as $key =&gt; $value) {
if (array_search($key, $suppress) === false)
if (!in_array($key, $suppress))
$fields[$key] = $value;
}
return $fields;
@ -180,8 +204,9 @@ class w3form
{
$fields = explode(&#039;###&#039;, $form);
$field = [];
$fieldsCount = count($fields);
for ($i = 1; $i &lt; count($fields); $i = $i + 2) {
for ($i = 1; $i &lt; $fieldsCount; $i += 2) {
$attribute = explode(&#039;;&#039;, trim($fields[$i]));
foreach ($attribute as $attribute) {
$nameValue = explode(&#039;:&#039;, trim($attribute));
@ -198,7 +223,8 @@ class w3form
public function formOutput($sent = false): void
{
echo &#039;&lt;div class=&quot;textItem secondItem&quot;&gt;&lt;form action=&quot;&quot; method=&quot;POST&quot; class=&quot;form-horizontal&quot;&gt;&#039;;
$form_action = $this-&gt;cSession-&gt;url(&#039;front_content.php?idcat=&#039; . cRegistry::getCategoryId() . &#039;&amp;idart=&#039; . cRegistry::getArticleId());
echo &#039;&lt;form action=&quot;&#039; . $form_action . &#039;&quot; method=&quot;post&quot; class=&quot;form-horizontal&quot;&gt;&#039;;
echo &#039;&lt;input type=&quot;hidden&quot; name=&quot;sent&quot; value=&quot;true&quot; /&gt;&#039;;
$form = $this-&gt;form[&#039;form&#039;];
$formData = $this-&gt;formInterpretation($form);
@ -211,45 +237,60 @@ class w3form
echo $item;
}
}
echo &#039;&lt;/form&gt;&lt;/div&gt;&#039;;
echo &#039;&lt;/form&gt;&#039;;
}
public function formField($attribute, $sent): void
{
$style = &#039;&#039;;
$value = &#039;&#039;;
$parameter = &quot;name=\&quot;{$attribute[&#039;name&#039;]}\&quot;&quot;;
if ($sent &amp;&amp; !$this-&gt;formFieldCorrect($attribute))
$style = &quot;style=\&quot;background-color:{$this-&gt;form[&#039;colorError&#039;]};\&quot;&quot;;
switch ($attribute[&#039;type&#039;]) {
case &#039;select&#039;:
case &#039;password&#039;:
case &#039;text&#039;:
if (!empty($attribute[&#039;size&#039;]))
$parameter .= &quot; size=\&quot;{$attribute[&#039;size&#039;]}\&quot;&quot;;
break;
$parameter = empty($attribute[&#039;id&#039;]) ? &#039;id=&quot;&#039; . $attribute[&#039;name&#039;] . &#039;&quot;&#039; : &#039;id=&quot;&#039; . $attribute[&#039;id&#039;] . &#039;&quot;&#039;;
$parameter .= &#039; name=&quot;&#039; . $attribute[&#039;name&#039;] . &#039;&quot;&#039;;
if ($sent &amp;&amp; !$this-&gt;formFieldCorrect($attribute)) {
$style = &#039;style=&quot;background-color: &#039; . $this-&gt;form[&#039;colorError&#039;] . &#039;;&quot;&#039;;
}
if (!empty($attribute[&#039;class&#039;])) {
$parameter .= &#039; class=&quot;&#039; . $attribute[&#039;class&#039;] . &#039;&quot;&#039;;
}
if (!empty($attribute[&#039;placeholder&#039;])) {
$parameter .= &#039; placeholder=&quot;&#039; . $attribute[&#039;placeholder&#039;] . &#039;&quot;&#039;;
}
switch ($attribute[&#039;type&#039;]) {
case &#039;textarea&#039;:
case &#039;text&#039;:
if (!empty($attribute[&#039;size&#039;]))
$parameter .= &quot; size=\&quot;{$attribute[&#039;size&#039;]}\&quot;&quot;;
if (!empty($attribute[&#039;value&#039;]))
if (!empty($attribute[&#039;size&#039;])) {
$parameter .= &#039; size=&quot;&#039; . $attribute[&#039;size&#039;] . &#039;&quot;&#039;;
}
if (!empty($attribute[&#039;value&#039;])) {
$value = $attribute[&#039;value&#039;];
if (!empty($_POST[&quot;{$attribute[&#039;name&#039;]}&quot;]))
}
if (!empty($_POST[&quot;{$attribute[&#039;name&#039;]}&quot;])) {
$value = $_POST[&quot;{$attribute[&#039;name&#039;]}&quot;];
}
break;
case &#039;select&#039;:
case &#039;password&#039;:
if (!empty($attribute[&#039;size&#039;])) {
$parameter .= &#039; size=&quot;&#039; . $attribute[&#039;size&#039;] . &#039;&quot;&#039;;
}
break;
}
if (isset($attribute[&#039;required&#039;]) || isset($attribute[&#039;mandantory&#039;])) {
$parameter .= &#039; required&#039;;
}
switch ($attribute[&#039;type&#039;]) {
case &#039;captcha&#039;:
if ($this-&gt;captchaInstalled) {
if ($sent) {
$captcha = @$_POST[&#039;ct_captcha&#039;];
$capId = @$_POST[&#039;captcha_id&#039;];
$captcha = @$_POST[&#039;lets_check&#039;];
$securimage = new Securimage();
if (!$securimage-&gt;check($captcha)) {
@ -260,9 +301,10 @@ class w3form
}
// show captcha HTML using Securimage::getCaptchaHtml()
$options = [];
$options[&#039;input_name&#039;] = &#039;ct_captcha&#039;; // change name of input element for form post input_text
$options[&#039;show_audio_button&#039;] = false;
$options[&#039;input_name&#039;] = &#039;lets_check&#039;; // change name of input element for form post input_text
$options[&#039;input_text&#039;] = mi18n(&quot;Zeichen eingeben&quot;);
$options[&#039;input_required&#039;] = false;
$options[&#039;input_required&#039;] = true;
if (!empty($_SESSION[&#039;ctform&#039;][&#039;captcha_error&#039;])) {
// error html to show in captcha output
@ -272,13 +314,13 @@ class w3form
echo &quot;&lt;div id=&#039;captcha_container_1&#039;&gt;\n&quot;;
echo Securimage::getCaptchaHtml($options);
echo &quot;\n&lt;/div&gt;\n&quot;;
echo &#039;&lt;script src=&quot;securimage/securimage.js&quot;&gt;&lt;/script&gt;&#039;;
}
break;
case &#039;text&#039;:
echo &quot;&lt;input type=\&quot;text\&quot; $parameter value=\&quot;$value\&quot; $style /&gt;&quot;;
break;
case &#039;email&#039;:
case &#039;password&#039;:
echo &quot;&lt;input type=\&quot;password\&quot; $parameter value=\&quot;$value\&quot; $style /&gt;&quot;;
echo &#039;&lt;input type=&quot;&#039;.$attribute[&#039;type&#039;].&#039;&quot; &#039;.$parameter.&#039; value=&quot;&#039;.$value.&#039;&quot; &#039;.$style.&#039; /&gt;&#039;;
break;
case &#039;textarea&#039;:
echo &quot;&lt;textarea name=\&quot;{$attribute[&#039;name&#039;]}\&quot; cols=\&quot;&quot;;
@ -289,27 +331,22 @@ class w3form
break;
case &#039;select&#039;:
echo &quot;&lt;select $parameter $style&gt;&quot;;
for ($i = 0; $i &lt; (is_countable($attribute[&#039;option&#039;]) ? count($attribute[&#039;option&#039;]) : 0); $i++) {
$itemsCount = is_countable($attribute[&#039;option&#039;]) ? count($attribute[&#039;option&#039;]) : 0;
for ($i = 0; $i &lt; (is_countable($attribute[&#039;option&#039;]) ? $itemsCount : 0); $i++) {
if (!empty($attribute[&#039;optionvalue&#039;][$i])) {
if (!empty($_POST[&quot;{$attribute[&#039;name&#039;]}&quot;]) &amp;&amp; $_POST[&quot;{$attribute[&#039;name&#039;]}&quot;] == $attribute[&#039;optionvalue&#039;][$i]) {
echo &quot;&lt;option value=\&quot;{$attribute[&#039;optionvalue&#039;][$i]}\&quot; selected=\&quot;selected\&quot;&gt;{$attribute[&#039;option&#039;][$i]}&lt;/option&gt;\n&quot;;
} elseif (empty($_POST[&quot;{$attribute[&#039;name&#039;]}&quot;]) &amp;&amp; !empty($attribute[&#039;optionvalue&#039;][$i]) &amp;&amp; $attribute[&#039;optionvalue&#039;][$i] == $attribute[&#039;value&#039;]) {
echo &quot;&lt;option value=\&quot;{$attribute[&#039;optionvalue&#039;][$i]}\&quot; selected=\&quot;selected\&quot;&gt;{$attribute[&#039;option&#039;][$i]}&lt;/option&gt;\n&quot;;
} else {
if (empty($_POST[&quot;{$attribute[&#039;name&#039;]}&quot;]) &amp;&amp; !empty($attribute[&#039;optionvalue&#039;][$i]) &amp;&amp; $attribute[&#039;optionvalue&#039;][$i] == $attribute[&#039;value&#039;]) {
echo &quot;&lt;option value=\&quot;{$attribute[&#039;optionvalue&#039;][$i]}\&quot; selected=\&quot;selected\&quot;&gt;{$attribute[&#039;option&#039;][$i]}&lt;/option&gt;\n&quot;;
} else {
echo &quot;&lt;option value=\&quot;{$attribute[&#039;optionvalue&#039;][$i]}\&quot;&gt;{$attribute[&#039;option&#039;][$i]}&lt;/option&gt;\n&quot;;
}
echo &quot;&lt;option value=\&quot;{$attribute[&#039;optionvalue&#039;][$i]}\&quot;&gt;{$attribute[&#039;option&#039;][$i]}&lt;/option&gt;\n&quot;;
}
} elseif (!empty($_POST[&quot;{$attribute[&#039;name&#039;]}&quot;]) &amp;&amp; $_POST[&quot;{$attribute[&#039;name&#039;]}&quot;] == $attribute[&#039;option&#039;][$i]) {
echo &quot;&lt;option selected=\&quot;selected\&quot;&gt;{$attribute[&#039;option&#039;][$i]}&lt;/option&gt;\n&quot;;
} elseif (empty($_POST[&quot;{$attribute[&#039;name&#039;]}&quot;]) &amp;&amp; $attribute[&#039;option&#039;][$i] == $attribute[&#039;value&#039;]) {
echo &quot;&lt;option selected=\&quot;selected\&quot;&gt;{$attribute[&#039;option&#039;][$i]}&lt;/option&gt;\n&quot;;
} else {
if (!empty($_POST[&quot;{$attribute[&#039;name&#039;]}&quot;]) &amp;&amp; $_POST[&quot;{$attribute[&#039;name&#039;]}&quot;] == $attribute[&#039;option&#039;][$i]) {
echo &quot;&lt;option selected=\&quot;selected\&quot;&gt;{$attribute[&#039;option&#039;][$i]}&lt;/option&gt;\n&quot;;
} else {
if (empty($_POST[&quot;{$attribute[&#039;name&#039;]}&quot;]) &amp;&amp; $attribute[&#039;option&#039;][$i] == $attribute[&#039;value&#039;]) {
echo &quot;&lt;option selected=\&quot;selected\&quot;&gt;{$attribute[&#039;option&#039;][$i]}&lt;/option&gt;\n&quot;;
} else {
echo &quot;&lt;option&gt;{$attribute[&#039;option&#039;][$i]}&lt;/option&gt;\n&quot;;
}
}
echo &quot;&lt;option&gt;{$attribute[&#039;option&#039;][$i]}&lt;/option&gt;\n&quot;;
}
}
echo &quot;&lt;/select&gt;&quot;;
@ -322,12 +359,10 @@ class w3form
} else {
echo &quot;&lt;label $style&gt;&lt;input type=\&quot;checkbox\&quot; $parameter value=\&quot;{$attribute[&#039;value&#039;]}\&quot;/&gt;&lt;/label&gt;&quot;;
}
} elseif (!empty($attribute[&#039;selected&#039;]) &amp;&amp; $attribute[&#039;selected&#039;] == &#039;true&#039;) {
echo &quot;&lt;input type=\&quot;checkbox\&quot; $parameter value=\&quot;{$attribute[&#039;value&#039;]}\&quot; checked=\&quot;checked\&quot;/&gt;&quot;;
} else {
if (!empty($attribute[&#039;selected&#039;]) &amp;&amp; $attribute[&#039;selected&#039;] == &#039;true&#039;) {
echo &quot;&lt;input type=\&quot;checkbox\&quot; $parameter value=\&quot;{$attribute[&#039;value&#039;]}\&quot; checked=\&quot;checked\&quot;/&gt;&quot;;
} else {
echo &quot;&lt;input type=\&quot;checkbox\&quot; $parameter value=\&quot;{$attribute[&#039;value&#039;]}\&quot;/&gt;&quot;;
}
echo &quot;&lt;input type=\&quot;checkbox\&quot; $parameter value=\&quot;{$attribute[&#039;value&#039;]}\&quot;/&gt;&quot;;
}
break;
case &#039;radio&#039;:
@ -337,12 +372,10 @@ class w3form
} else {
echo &quot;&lt;input type=\&quot;radio\&quot; $parameter value=\&quot;{$attribute[&#039;value&#039;]}\&quot; /&gt;&quot;;
}
} elseif (!empty($attribute[&#039;selected&#039;]) &amp;&amp; $attribute[&#039;selected&#039;] == &#039;true&#039;) {
echo &quot;&lt;input type=\&quot;radio\&quot; $parameter value=\&quot;{$attribute[&#039;value&#039;]}\&quot; checked=\&quot;checked\&quot;/&gt;&quot;;
} else {
if (!empty($attribute[&#039;selected&#039;]) &amp;&amp; $attribute[&#039;selected&#039;] == &#039;true&#039;) {
echo &quot;&lt;input type=\&quot;radio\&quot; $parameter value=\&quot;{$attribute[&#039;value&#039;]}\&quot; checked=\&quot;checked\&quot;/&gt;&quot;;
} else {
echo &quot;&lt;input type=\&quot;radio\&quot; $parameter value=\&quot;{$attribute[&#039;value&#039;]}\&quot;/&gt;&quot;;
}
echo &quot;&lt;input type=\&quot;radio\&quot; $parameter value=\&quot;{$attribute[&#039;value&#039;]}\&quot;/&gt;&quot;;
}
break;
}
@ -356,7 +389,7 @@ class w3form
switch ($field[&#039;type&#039;]) {
case &#039;captcha&#039;:
if ($this-&gt;captchaInstalled) {
$captcha = @$_POST[&#039;ct_captcha&#039;];
$captcha = @$_POST[&#039;lets_check&#039;];
$capId = @$_POST[&#039;captcha_id&#039;];
$securimage = new Securimage();
if (!$securimage-&gt;check($captcha, $capId, true)) {
@ -377,7 +410,13 @@ class w3form
private function success(): void
{
if ($this-&gt;sendEmail()) {
echo $this-&gt;form[&#039;answer&#039;];
$answer = trim($this-&gt;form[&#039;answer&#039;]);
if (mb_strlen($answer) &gt; 0) {
echo $this-&gt;form[&#039;answer&#039;];
} else {
echo &#039;&lt;span style=&quot;color:green;&quot;&gt;&#039; . mi18n(&quot;Form has been successfully send.&quot;) . &#039;&lt;/span&gt;&#039;;
}
} else {
echo &#039;&lt;span style=&quot;color:red;&quot;&gt;&#039; . mi18n(&quot;Es ist ein Fehler aufgetreten!&lt;br&gt;Bitte versuchen Sie es später noch einmal.&quot;) . &#039;&lt;/span&gt;&#039;;
}
@ -389,10 +428,8 @@ class w3form
$tmp_name = rtrim($field[&#039;name&#039;], &#039;[0]&#039;);
preg_match(&#039;/\[(\d*)\]/&#039;, $field[&#039;name&#039;], $matches);
$bEmptyPost = false;
$bIsPostArray = false;
$sPostFieldValue = $_POST[$tmp_name];
if (is_array($_POST[$tmp_name])) {
$bIsPostArray == true;
$sPostFieldValue = $_POST[$tmp_name][$matches[1]];
if (empty($_POST[$tmp_name][$matches[1]])) {
$bEmptyPost = true;
@ -465,10 +502,7 @@ class w3form
// längenbereich bei allen typen prüfen
if (!empty($field[&#039;minlength&#039;]) &amp;&amp; strlen($sPostFieldValue) &lt; $field[&#039;minlength&#039;])
return false;
if (!empty($field[&#039;maxlength&#039;]) &amp;&amp; strlen($sPostFieldValue) &gt; $field[&#039;maxlength&#039;])
return false;
return true;
return !(!empty($field[&#039;maxlength&#039;]) &amp;&amp; strlen($sPostFieldValue) &gt; $field[&#039;maxlength&#039;]);
}
public function process(): void
@ -484,23 +518,27 @@ class w3form
}
if (isset($edit) &amp;&amp; $edit) {
echo &quot;&lt;h1&gt;&quot; . mi18n(&quot;Formularkonfiguration&quot;) . &quot;&lt;/h1&gt;&quot;;
echo &quot;&lt;p&gt;&quot; . mi18n(&quot;Hier ist das Formular sowie der Text einzugeben, der zusammen mit dem Formular ausgegeben werden soll:&quot;) . &quot;&lt;/p&gt;&quot;;
echo &quot;CMS_HTML[0]&quot;;
echo &quot;&lt;p&gt;&quot; . mi18n(&quot;Hier ist die Ausgabe einzugeben, die erscheint, wenn das Formular erfolgreich prozessiert worden ist:&quot;) . &quot;&lt;/p&gt;&quot;;
echo &quot;CMS_HTML[1]&quot;;
if (cRegistry::isBackendEditMode()) {
echo &quot;&lt;hr&gt;&quot;;
echo &quot;&lt;h3&gt;&quot; . mi18n(&quot;Formularkonfiguration&quot;) . &quot;&lt;/h3&gt;&quot;;
echo &quot;&lt;h4&gt;&quot; . mi18n(&quot;Hier ist das Formular sowie der Text einzugeben, der zusammen mit dem Formular ausgegeben werden soll:&quot;) . &quot;&lt;/h4&gt;&quot;;
echo &quot;CMS_HTML[100]&quot;;
echo &quot;&lt;h4&gt;&quot; . mi18n(&quot;Hier ist die Ausgabe einzugeben, die erscheint, wenn das Formular erfolgreich verschickt wurde:&quot;) . &quot;&lt;/h4&gt;&quot;;
echo &quot;CMS_HTML[101]&quot;;
echo &quot;&lt;hr&gt;&quot;;
} else {
$form = new w3form($captchaInstalled);
$form = new FormGenerator($captchaInstalled, $sess);
$form-&gt;addEmailAdress(&quot;CMS_VALUE[0]&quot;);
$form-&gt;setEmailSubject(&quot;CMS_VALUE[1]&quot;);
$form-&gt;setEmailFrom(&quot;CMS_VALUE[2]&quot;, &quot;CMS_VALUE[3]&quot;);
$form-&gt;setBackgroundError(&quot;CMS_VALUE[4]&quot;);
$form-&gt;setForm(&quot;CMS_HTML[0]&quot;);
$form-&gt;setAnswer(&quot;CMS_HTML[1]&quot;);
$form-&gt;setForm(&quot;CMS_HTML[100]&quot;);
$form-&gt;setAnswer(&quot;CMS_HTML[101]&quot;);
$form-&gt;process();
}
?&gt;</output>
?&gt;
</output>
</module>
<jsfiles/>
<tplfiles/>

Datei anzeigen

@ -1,398 +0,0 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<modulepackage><package_guid/>
<package_data>a:5:{s:7:"jsfiles";a:0:{}s:8:"tplfiles";a:0:{}s:8:"cssfiles";a:0:{}s:7:"layouts";a:0:{}s:12:"translations";a:0:{}}</package_data>
<module><name>KontaktForm_Valid</name>
<description>&lt;Ihre Modulbeschreibung&gt;
Autor:
Version</description>
<type/>
<input>?&gt;&lt;?php
/**************************************************
* CONTENIDO MODULE - INPUT
*
* Modulname : w3concepts.form.v1
* Author : Andreas Kummer
* Copyright : mumprecht &amp; kummer w3concepts
* Created : 20-08-2004
* Modified : 20-08-2004
* Modified : 24-08-2013, Murat Purc, adapted to newer CONTENIDO (4.8) version
*************************************************/
echo &quot;
&lt;table cellspacing='0' cellpadding='10' border='0'&gt;
&lt;tr&gt;
&lt;td&gt;&quot; . mi18n(&quot;Zieladresse (alias@mydomain.com):&quot;) . &quot;&lt;/td&gt;
&lt;td&gt;&lt;input type='text' name=\&quot;CMS_VAR[0]\&quot; value=\&quot;CMS_VALUE[0]\&quot; size='30' /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&quot; . mi18n(&quot;Betreff:&quot;) . &quot;&lt;/td&gt;
&lt;td&gt;&lt;input type='text' name=\&quot;CMS_VAR[1]\&quot; value=\&quot;CMS_VALUE[1]\&quot; size='30' /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&quot; . mi18n(&quot;Antwortadresse (alias@mydomain.com):&quot;) . &quot;&lt;/td&gt;
&lt;td&gt;&lt;input type='text' name=\&quot;CMS_VAR[2]\&quot; value=\&quot;CMS_VALUE[2]\&quot; size='30' /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&quot; . mi18n(&quot;Emailname (z.B. Vorname Name):&quot;) . &quot;&lt;/td&gt;
&lt;td&gt;&lt;input type='text' name=\&quot;CMS_VAR[3]\&quot; value=\&quot;CMS_VALUE[3]\&quot; size='30' /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&quot; . mi18n(&quot;Hintergrundfarbe bei Fehlern (z.B. red):&quot;) . &quot;&lt;/td&gt;
&lt;td&gt;&lt;input type='text' name=\&quot;CMS_VAR[4]\&quot; value=\&quot;CMS_VALUE[4]\&quot; size='30' /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&quot;;
</input>
<output>&lt;?php
/**************************************************
* CONTENIDO MODULE - OUTPUT
*
* Modulname : w3concepts.form.v1
* Author : Andreas Kummer
* Copyright : mumprecht &amp; kummer w3concepts
* Created : 20-08-2004
* Modified : 20-08-2004
* Modified : 24-08-2013, Murat Purc, adapted to newer CONTENIDO (4.8) and PHP (5.3/5.4) versions
*************************************************/
class w3form {
private $email;
private $unraveled = array();
private $form;
private $formField = array();
public function __construct() {
$this-&gt;email = array(
'adresses' =&gt; '',
'from' =&gt; array(
'name' =&gt; '',
'email' =&gt; ''
),
'message' =&gt; '',
'subject' =&gt; ''
);
$this-&gt;form = array(
'form' =&gt; '',
'answer' =&gt; '',
'colorError' =&gt; ''
);
}
private function sendEmail() {
$this-&gt;unravel($this-&gt;suppress('sent'));
$this-&gt;generateEmailMessage();
mail(
$this-&gt;email['adresses'],
$this-&gt;email['subject'],
$this-&gt;email['message'],
sprintf(
&quot;From: %s &lt;%s&gt;\nReply-To: %s\nX-Mailer: PHP/%s&quot;,
$this-&gt;email['from']['name'],
$this-&gt;email['from']['email'],
$this-&gt;email['from']['email'],
phpversion()
)
);
}
private function unravel($toUnravel, $prefix = '') {
foreach ($toUnravel as $key =&gt; $value) {
if (is_array($value)) {
$this-&gt;unravel($value, $key . ' ');
} else {
$this-&gt;unraveled[&quot;{$prefix}{$key}&quot;] = $value;
}
}
}
private function add2Message($key, $value) {
if (strlen($key) &gt; 25 OR strlen($value) &gt; 54) {
$this-&gt;email['message'] .= &quot;$key\n$value\n&quot;;
} else {
$this-&gt;email['message'] .= $key;
$this-&gt;email['message'] .= str_repeat(' ', 25 - strlen($key));
$this-&gt;email['message'] .= &quot;$value\n&quot;;
}
}
private function generateEmailMessage() {
if ($this-&gt;unraveled)
foreach ($this-&gt;unraveled as $key =&gt; $value) {
$this-&gt;add2Message($key, $value);
}
}
private function suppress() {
$suppress = func_get_args();
foreach ($_POST as $key =&gt; $value) {
if (array_search($key, $suppress) === false)
$fields[$key] = $value;
}
return $fields;
}
public function addEmailAdress($email) {
if (empty($this-&gt;emailAdresses)) {
$this-&gt;email['adresses'] .= &quot;$email&quot;;
} else {
$this-&gt;email['adresses'] .= &quot;, $email&quot;;
}
}
public function setEmailSubject($subject) {
$this-&gt;email['subject'] = $subject;
}
public function setEmailFrom($email, $name) {
$this-&gt;email['from']['email'] = $email;
$this-&gt;email['from']['name'] = $name;
}
public function setForm($form) {
$this-&gt;form['form'] = $form;
}
public function setAnswer($answer) {
$this-&gt;form['answer'] = $answer;
}
public function setBackgroundError($color) {
$this-&gt;form['colorError'] = $color;
}
public function formInterpretation(&amp;$form) {
$fields = explode('###', $form);
$field = array();
for ($i = 1; $i &lt; count($fields); $i = $i + 2) {
$attributte = explode(';', trim($fields[$i]));
foreach ($attributte as $attribute) {
$nameValue = explode(':', trim($attribute));
if ($nameValue[0] != 'option' &amp;&amp; $nameValue[0] != 'optionvalue') {
$field[&quot;{$fields[$i]}&quot;][&quot;{$nameValue[0]}&quot;] = $nameValue[1];
} else {
$field[&quot;{$fields[$i]}&quot;][&quot;{$nameValue[0]}&quot;][] = $nameValue[1];
}
}
}
return $field;
}
public function formOutput($sent = false) {
echo '&lt;div class=&quot;textItem secondItem&quot;&gt;&lt;form action=&quot;&quot; method=&quot;POST&quot; class=&quot;form-horizontal&quot;&gt;';
echo '&lt;input type=&quot;hidden&quot; name=&quot;sent&quot; value=&quot;true&quot; /&gt;';
$form = $this-&gt;form['form'];
$formData = $this-&gt;formInterpretation($form);
$form = explode('###', $form);
foreach ($form as $item) {
if (!empty($formData[&quot;{$item}&quot;])) {
$this-&gt;formField($formData[&quot;{$item}&quot;], $sent);
} else {
echo $item;
}
}
echo '&lt;/form&gt;&lt;/div&gt;';
}
public function formField($attribute, $sent) {
$parameter = &quot;name=\&quot;{$attribute['name']}\&quot;&quot;;
if ($sent &amp;&amp; !$this-&gt;formFieldCorrect($attribute))
$style = &quot;style=\&quot;background-color:{$this-&gt;form['colorError']};\&quot;&quot;;
switch ($attribute['type']) {
case 'select':
case 'password':
case 'text':
if (!empty($attribute['size']))
$parameter .= &quot; size=\&quot;{$attribute['size']}\&quot;&quot;;
break;
}
switch ($attribute['type']) {
case 'textarea':
case 'text':
if (!empty($attribute['size']))
$parameter .= &quot; size=\&quot;{$attribute['size']}\&quot;&quot;;
if (!empty($attribute['value']))
$value = $attribute['value'];
if (!empty($_POST[&quot;{$attribute['name']}&quot;]))
$value = $_POST[&quot;{$attribute['name']}&quot;];
break;
}
switch ($attribute['type']) {
case 'text':
echo &quot;&lt;input type=\&quot;text\&quot; $parameter value=\&quot;$value\&quot; $style /&gt;&quot;;
break;
case 'password':
echo &quot;&lt;input type=\&quot;password\&quot; $parameter value=\&quot;$value\&quot; $style /&gt;&quot;;
break;
case 'textarea':
echo &quot;&lt;textarea name=\&quot;{$attribute['name']}\&quot; cols=\&quot;&quot;;
echo (empty($attribute['cols'])) ? ('20') : ($attribute['cols']);
echo &quot;\&quot; rows=\&quot;&quot;;
echo (empty($attribute['rows'])) ? ('2') : ($attribute['rows']);
echo &quot;\&quot; wrap=\&quot;virtual\&quot; $style&gt;$value&lt;/textarea&gt;&quot;;
break;
case 'select':
echo &quot;&lt;select $parameter $style&gt;&quot;;
for ($i = 0; $i &lt; count($attribute['option']); $i++) {
if (!empty($attribute['optionvalue'][$i])) {
if (!empty($_POST[&quot;{$attribute['name']}&quot;]) &amp;&amp; $_POST[&quot;{$attribute['name']}&quot;] == $attribute['optionvalue'][$i]) {
echo &quot;&lt;option value=\&quot;{$attribute['optionvalue'][$i]}\&quot; selected=\&quot;selected\&quot;&gt;{$attribute['option'][$i]}&lt;/option&gt;\n&quot;;
} else {
if (empty($_POST[&quot;{$attribute['name']}&quot;]) &amp;&amp; !empty($attribute['optionvalue'][$i]) &amp;&amp; $attribute['optionvalue'][$i] == $attribute['value']) {
echo &quot;&lt;option value=\&quot;{$attribute['optionvalue'][$i]}\&quot; selected=\&quot;selected\&quot;&gt;{$attribute['option'][$i]}&lt;/option&gt;\n&quot;;
} else {
echo &quot;&lt;option value=\&quot;{$attribute['optionvalue'][$i]}\&quot;&gt;{$attribute['option'][$i]}&lt;/option&gt;\n&quot;;
}
}
} else {
if (!empty($_POST[&quot;{$attribute['name']}&quot;]) &amp;&amp; $_POST[&quot;{$attribute['name']}&quot;] == $attribute['option'][$i]) {
echo &quot;&lt;option selected=\&quot;selected\&quot;&gt;{$attribute['option'][$i]}&lt;/option&gt;\n&quot;;
} else {
if (empty($_POST[&quot;{$attribute['name']}&quot;]) &amp;&amp; $attribute['option'][$i] == $attribute['value']) {
echo &quot;&lt;option selected=\&quot;selected\&quot;&gt;{$attribute['option'][$i]}&lt;/option&gt;\n&quot;;
} else {
echo &quot;&lt;option&gt;{$attribute['option'][$i]}&lt;/option&gt;\n&quot;;
}
}
}
}
echo &quot;&lt;/select&gt;&quot;;
break;
case 'checkbox':
$formId = preg_split('[\[|\]]', $attribute['name']);
if ($sent) {
if ($_POST[&quot;{$formId[0]}&quot;][&quot;{$formId[1]}&quot;] == $attribute['value']) {
echo &quot;&lt;input type=\&quot;checkbox\&quot; $parameter value=\&quot;{$attribute['value']}\&quot; checked=\&quot;checked\&quot;/&gt;&quot;;
} else {
echo &quot;&lt;input type=\&quot;checkbox\&quot; $parameter value=\&quot;{$attribute['value']}\&quot;/&gt;&quot;;
}
} else {
if (!empty($attribute['selected']) &amp;&amp; $attribute['selected'] == 'true') {
echo &quot;&lt;input type=\&quot;checkbox\&quot; $parameter value=\&quot;{$attribute['value']}\&quot; checked=\&quot;checked\&quot;/&gt;&quot;;
} else {
echo &quot;&lt;input type=\&quot;checkbox\&quot; $parameter value=\&quot;{$attribute['value']}\&quot;/&gt;&quot;;
}
}
break;
case 'radio':
if (!empty($_POST[&quot;{$attribute['name']}&quot;])) {
if ($_POST[&quot;{$attribute['name']}&quot;] == $attribute['value']) {
echo &quot;&lt;input type=\&quot;radio\&quot; $parameter value=\&quot;{$attribute['value']}\&quot; checked=\&quot;checked\&quot;/&gt;&quot;;
} else {
echo &quot;&lt;input type=\&quot;radio\&quot; $parameter value=\&quot;{$attribute['value']}\&quot; /&gt;&quot;;
}
} else {
if (!empty($attribute['selected']) &amp;&amp; $attribute['selected'] == 'true') {
echo &quot;&lt;input type=\&quot;radio\&quot; $parameter value=\&quot;{$attribute['value']}\&quot; checked=\&quot;checked\&quot;/&gt;&quot;;
} else {
echo &quot;&lt;input type=\&quot;radio\&quot; $parameter value=\&quot;{$attribute['value']}\&quot;/&gt;&quot;;
}
}
break;
}
}
private function formComplete() {
$form = $this-&gt;form['form'];
$fields = $this-&gt;formInterpretation($form);
foreach ($fields as $field) {
if (!$this-&gt;formFieldCorrect($field)) {
return false;
}
}
return true;
}
private function success() {
$this-&gt;sendEmail();
echo $this-&gt;form['answer'];
}
private function formFieldCorrect(&amp;$field) {
// prüfung, ob pflichtfeld vorhanden
if (!empty($field['mandatory']) &amp;&amp; $field['mandatory'] == 'true' &amp;&amp; empty($_POST[&quot;{$field['name']}&quot;]))
return false;
// wenn das formularfeld kein pflichtfeld und nicht vorhanden ist, true zurück geben
if (empty($_POST[&quot;{$field['name']}&quot;]))
return true;
// regular expression prüfungen
if (!empty($field['valid']) &amp;&amp; $field['valid'] == 'simpletext' &amp;&amp; !preg_match(&quot;/^[öäüéàèâêîça-z-]*$/i&quot;, $_POST[&quot;{$field['name']}&quot;]))
return false;
if (!empty($field['valid']) &amp;&amp; $field['valid'] == 'text' &amp;&amp; !preg_match(&quot;/^[ .,;!?()öäüéàèâêîça-z-]*$/i&quot;, $_POST[&quot;{$field['name']}&quot;]))
return false;
if (!empty($field['valid']) &amp;&amp; $field['valid'] == 'integer' &amp;&amp; !preg_match(&quot;/^[0-9]*$/&quot;, $_POST[&quot;{$field['name']}&quot;]))
return false;
if (!empty($field['valid']) &amp;&amp; $field['valid'] == 'float' &amp;&amp; !preg_match(&quot;/^[0-9]*[.]{0,1}[0-9]*$/&quot;, $_POST[&quot;{$field['name']}&quot;]))
return false;
if (!empty($field['valid']) &amp;&amp; $field['valid'] == 'date' &amp;&amp; !preg_match(&quot;/^[0-9]{1,2}.[0-9]{1,2}.[0-9]{2}$/&quot;, $_POST[&quot;{$field['name']}&quot;]))
return false;
if (!empty($field['valid']) &amp;&amp; $field['valid'] == 'email' &amp;&amp; !preg_match(&quot;/^[öäüéàèâêîç_a-z0-9-]+(\.[öäüéàèâêîç_a-z0-9-]+)*@[öäüéàèâêîça-z0-9-]+(\.[öäüéàèâêîça-z0-9-]+)*$/i&quot;, $_POST[&quot;{$field['name']}&quot;]))
return false;
// grössenbereich bei integer und float prüfen
if (!empty($field['minvalue']) &amp;&amp; $_POST[&quot;{$field['name']}&quot;] &lt; $field['minvalue'])
return false;
if (!empty($field['maxvalue']) &amp;&amp; $_POST[&quot;{$field['name']}&quot;] &gt; $field['maxvalue'])
return false;
// längenbereich bei allen typen prüfen
if (!empty($field['minlength']) &amp;&amp; strlen($_POST[&quot;{$field['name']}&quot;]) &lt; $field['minlength'])
return false;
if (!empty($field['maxlength']) &amp;&amp; strlen($_POST[&quot;{$field['name']}&quot;]) &gt; $field['maxlength'])
return false;
return true;
}
public function process() {
if (!isset($_POST['sent'])) {
$this-&gt;formOutput();
} elseif ($this-&gt;formComplete()) {
$this-&gt;success();
} else {
$this-&gt;formOutput(true);
}
}
}
if (isset($edit) &amp;&amp; $edit) {
echo &quot;&lt;h1&gt;&quot; . mi18n(&quot;Formularkonfiguration&quot;) . &quot;&lt;/h1&gt;&quot;;
echo &quot;&lt;p&gt;&quot; . mi18n(&quot;Hier ist das Formular sowie der Text einzugeben, der zusammen mit dem Formular ausgegeben werden soll:&quot;) . &quot;&lt;/p&gt;&quot;;
echo &quot;CMS_HTML[0]&quot;;
echo &quot;&lt;p&gt;&quot; . mi18n(&quot;Hier ist die Ausgabe einzugeben, die erscheint, wenn das Formular erfolgreich prozessiert worden ist:&quot;) . &quot;&lt;/p&gt;&quot;;
echo &quot;CMS_HTML[1]&quot;;
} else {
$form = new w3form();
$form-&gt;addEmailAdress(&quot;CMS_VALUE[0]&quot;);
$form-&gt;setEmailSubject(&quot;CMS_VALUE[1]&quot;);
$form-&gt;setEmailFrom(&quot;CMS_VALUE[2]&quot;, &quot;CMS_VALUE[3]&quot;);
$form-&gt;setBackgroundError(&quot;CMS_VALUE[4]&quot;);
$form-&gt;setForm(&quot;CMS_HTML[0]&quot;);
$form-&gt;setAnswer(&quot;CMS_HTML[1]&quot;);
$form-&gt;process();
}
?&gt;
</output>
</module>
<jsfiles/>
<tplfiles/>
<cssfiles/>
<layouts/>
</modulepackage>