* * 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) */ $sFrontEndPath = cRegistry::getClientConfig(cRegistry::getClientId())['path']['frontend'] . 'securimage' . DIRECTORY_SEPARATOR; $captchaInstalled = false; if (is_readable($sFrontEndPath)) { require_once $sFrontEndPath . 'securimage.php'; require_once $sFrontEndPath . 'CaptchaObject.php'; require_once $sFrontEndPath . 'StorageAdapter/AdapterInterface.php'; $captchaInstalled = true; } class w3form { private array $email = ['adresses' => '', 'from' => ['name' => '', 'email' => ''], 'message' => '', 'subject' => '']; private array $unraveled = []; private array $form = ['form' => '', 'answer' => '', 'colorError' => '']; public function __construct(private bool $captchaInstalled) { } private function sendEmail(): bool { $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']; if ($oMailer->send()) { return true; } return false; } private function unravel($toUnravel, $prefix = ''): void { foreach ($toUnravel as $key => $value) { if (is_array($value)) { $this->unravel($value, $key . ' '); } else { $this->unraveled["{$prefix}{$key}"] = $value; } } } private function add2Message($key, $value): void { if (strlen($key) > 25 or strlen($value) > 54) { $this->email['message'] .= "$key\n$value\n"; } else { $this->email['message'] .= $key; $this->email['message'] .= str_repeat(' ', 25 - strlen($key)); $this->email['message'] .= "$value\n"; } } private function generateEmailMessage(): void { if ($this->unraveled) foreach ($this->unraveled as $key => $value) { $this->add2Message($key, $value); } } private function suppress(): array { $fields = []; $suppress = func_get_args(); foreach ($_POST as $key => $value) { if (array_search($key, $suppress) === false) $fields[$key] = $value; } return $fields; } public function addEmailAdress($email): void { if (empty($this->emailAdresses)) { $this->email['adresses'] .= "$email"; } else { $this->email['adresses'] .= ", $email"; } } public function setEmailSubject($subject): void { $this->email['subject'] = $subject; } public function setEmailFrom($email, $name): void { $this->email['from']['email'] = $email; $this->email['from']['name'] = $name; } public function setForm($form): void { $this->form['form'] = $form; } public function setAnswer($answer): void { $this->form['answer'] = $answer; } public function setBackgroundError($color): void { $this->form['colorError'] = $color; } public function formInterpretation(&$form): array { $fields = explode('###', $form); $field = []; for ($i = 1; $i < count($fields); $i = $i + 2) { $attribute = explode(';', trim($fields[$i])); foreach ($attribute as $attribute) { $nameValue = explode(':', trim($attribute)); if ($nameValue[0] != 'option' && $nameValue[0] != 'optionvalue') { $field["{$fields[$i]}"]["{$nameValue[0]}"] = $nameValue[1]; } else { $field["{$fields[$i]}"]["{$nameValue[0]}"][] = $nameValue[1]; } } } return $field; } public function formOutput($sent = false): void { echo '
'; } 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; } switch ($attribute['type']) { case 'textarea': case 'text': if (!empty($attribute['size'])) $parameter .= ' size="' . $attribute['size'] . '"'; if (!empty($attribute['value'])) $value = $attribute['value']; if (!empty($_POST["{$attribute['name']}"])) $value = $_POST["{$attribute['name']}"]; break; } switch ($attribute['type']) { case 'captcha': if ($this->captchaInstalled) { if ($sent) { $captcha = @$_POST['ct_captcha']; $capId = @$_POST['captcha_id']; $securimage = new Securimage(); if (!$securimage->check($captcha)) { echo ''; } } // show captcha HTML using Securimage::getCaptchaHtml() $options = []; $options['input_name'] = 'ct_captcha'; // change name of input element for form post input_text $options['input_text'] = mi18n("Zeichen eingeben"); $options['input_required'] = false; if (!empty($_SESSION['ctform']['captcha_error'])) { // error html to show in captcha output $options['error_html'] = $_SESSION['ctform']['captcha_error']; } echo "" . mi18n("Hier ist das Formular sowie der Text einzugeben, der zusammen mit dem Formular ausgegeben werden soll:") . "
"; echo "CMS_HTML[100]"; echo "" . mi18n("Hier ist die Ausgabe einzugeben, die erscheint, wenn das Formular erfolgreich prozessiert worden ist:") . "
"; echo "CMS_HTML[101]"; } else { $form = new w3form($captchaInstalled); $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[100]"); $form->setAnswer("CMS_HTML[101]"); $form->process(); } ?>