9 private $dd =
'dbxContact|contactRequest';
11 private function h(
$value) {
12 return htmlspecialchars((
string)
$value, ENT_QUOTES,
'UTF-8');
15 private function mail_profile_options(array $extra = array()) {
16 $profile = trim((
string)
dbx()->get_config(
'dbxContact',
'mail_profile'));
24 private function mail_from_param(): array {
25 $from = trim((
string)
dbx()->get_config(
'dbxContact',
'mail_from'));
26 $fromName = trim((
string)
dbx()->get_config(
'dbxContact',
'mail_from_name'));
27 return array(
'email' => $from,
'name' => $fromName);
30 private function spam_reason(array $data):
string {
31 $mail =
dbx()->get_system_obj(
'dbxMail');
32 if (!is_object(
$mail) || !method_exists(
$mail,
'spam_reason_for_text')) {
36 $text = implode(
"\n", array(
37 (
string) ($data[
'name'] ??
''),
38 (
string) ($data[
'email'] ??
''),
39 (
string) ($data[
'phone'] ??
''),
40 (
string) ($data[
'subject'] ??
''),
41 (
string) ($data[
'message'] ??
''),
44 return (
string)
$mail->spam_reason_for_text($text);
47 private function mail_request(array $data,
int $rid) {
48 $to = trim((
string)
dbx()->get_config(
'dbxContact',
'mail_to'));
52 $from = $this->mail_from_param();
53 if (filter_var((
string)($from[
'email'] ??
''), FILTER_VALIDATE_EMAIL) ===
false) {
57 $prefix = trim((
string)
dbx()->get_config(
'dbxContact',
'mail_subject_prefix'));
58 $subject = trim($prefix .
': ' . ($data[
'subject'] ??
''));
60 $subject .=
' #' . $rid;
63 $tpl =
dbx()->get_system_obj(
'dbxTPL');
64 $html =
$tpl->get_tpl(
'dbxContact|mail-contact-request', array(
65 'name' => $this->h($data[
'name'] ??
''),
66 'email' => $this->h($data[
'email'] ??
''),
67 'phone' => $this->h($data[
'phone'] ??
''),
68 'subject' => $this->h($data[
'subject'] ??
''),
69 'message' => $this->h($data[
'message'] ??
''),
72 $text =
"Neue Kontaktanfrage #" . $rid .
"\n\n"
73 .
"Name: " . ($data[
'name'] ??
'') .
"\n"
74 .
"E-Mail: " . ($data[
'email'] ??
'') .
"\n"
75 .
"Telefon: " . ($data[
'phone'] ??
'') .
"\n"
76 .
"Betreff: " . ($data[
'subject'] ??
'') .
"\n\n"
77 . ($data[
'message'] ??
'');
79 $options = $this->mail_profile_options(array(
80 'reply_to' => array(
'email' => (
string) ($data[
'email'] ??
''),
'name' => (
string) ($data[
'name'] ??
'')),
84 return dbx()->send_mail($from, $to, $subject,
$html,
'html', array(),
$options);
87 private function mail_confirm(array $data,
int $rid) {
88 $to = trim((
string) ($data[
'email'] ??
''));
92 $from = $this->mail_from_param();
93 if (filter_var((
string)($from[
'email'] ??
''), FILTER_VALIDATE_EMAIL) ===
false) {
97 $subject = trim((
string)
dbx()->get_config(
'dbxContact',
'mail_confirm_subject'));
98 if ($subject ===
'') {
99 $subject =
'Ihre Kontaktanfrage';
102 $subject .=
' #' . $rid;
105 $phone = trim((
string) ($data[
'phone'] ??
''));
107 $tpl =
dbx()->get_system_obj(
'dbxTPL');
108 $html =
$tpl->get_tpl(
'dbxContact|mail-contact-confirm', array(
110 'name' => $this->h($data[
'name'] ??
''),
111 'phone' => $this->h($phone !==
'' ? $phone :
'-'),
112 'subject' => $this->h($data[
'subject'] ??
''),
113 'message' => $this->h($data[
'message'] ??
''),
116 $text =
"Ihre Anfrage ist eingegangen\n\n"
117 .
"Hallo " . ($data[
'name'] ??
'') .
",\n\n"
118 .
"vielen Dank fuer Ihre Nachricht. Wir haben Ihre Kontaktanfrage unter der Nummer #"
119 . $rid .
" erhalten und werden sie bearbeiten.\n\n"
120 .
"Betreff: " . ($data[
'subject'] ??
'') .
"\n"
121 .
"Telefon: " . ($phone !==
'' ? $phone :
'-') .
"\n\n"
122 . ($data[
'message'] ??
'') .
"\n\n"
123 .
"Wir melden uns so bald wie moeglich bei Ihnen. Sie muessen nichts weiter unternehmen.";
125 return dbx()->send_mail(
132 $this->mail_profile_options(array(
'text' => $text))
136 private function current_user_defaults() {
137 $uid = (int)
dbx()->user();
147 $name =
dbx()->user(
'name');
148 $email =
dbx()->user(
'email');
150 if ($name !==
'undef') {
151 $data[
'name'] = (string) $name;
154 if ($email !==
'undef') {
155 $data[
'email'] = (string) $email;
162 private function my_requests_button() {
163 if ((
int)
dbx()->
user() <= 0) {
167 return dbx()->get_system_obj(
'dbxTPL')->get_tpl(
'dbxContact|contact-my-requests-button');
170 private function snapshot_submitted_data($oForm) {
172 'name' =>
'words|min=2|max=160',
173 'email' =>
'email|max=180',
174 'phone' =>
'varchar|max=80',
175 'subject' =>
'varchar|min=3|max=220',
176 'message' =>
'*|min=8|max=5000',
181 $value = trim((
string) $oForm->get_post($name,
'',
$rules));
183 $oForm->set_post($name,
$value);
189 private function confirm_notes(array $data,
int $rid, ?
bool $confirmMailOk,
$form) {
191 $notes[] =
$form->get_fd_message(
'confirm_received');
192 $notes[] =
$form->format_fd_message(
197 $email = trim((
string) ($data[
'email'] ??
''));
198 $safeEmail = $this->h($email);
200 if ($confirmMailOk ===
true && $email !==
'') {
201 $notes[] =
$form->format_fd_message(
203 array(
'email' => $safeEmail)
205 } elseif ($confirmMailOk ===
false && $email !==
'') {
206 $notes[] =
$form->get_fd_message(
'confirm_mail_failed');
207 } elseif ($email !==
'') {
208 $notes[] =
$form->format_fd_message(
209 'confirm_mail_pending',
210 array(
'email' => $safeEmail)
215 $notes[] =
$form->get_fd_message(
'confirm_reply');
218 foreach ($notes as $note) {
219 $html .=
'<li>' . $note .
'</li>';
225 private function render_confirm(array $data,
int $rid, ?
bool $confirmMailOk,
$form) {
226 $tpl =
dbx()->get_system_obj(
'dbxTPL');
227 $phone = trim((
string) ($data[
'phone'] ??
''));
229 $html =
$tpl->get_tpl(
'dbxContact|contact-confirm', array(
231 'name' => $this->h($data[
'name'] ??
''),
232 'email' => $this->h($data[
'email'] ??
''),
233 'phone' => $this->h($phone !==
'' ? $phone :
'-'),
234 'subject' => $this->h($data[
'subject'] ??
''),
235 'message' => $this->h($data[
'message'] ??
''),
236 'confirm_lead' =>
$form->get_fd_message(
'confirm_lead'),
237 'confirm_notes' => $this->confirm_notes(
243 'my_requests' => $this->my_requests_button(),
244 'frame_id' =>
'dbx_contact_confirm',
245 'frame_panel_class' =>
'dbxForm_wrapper dbx-contact dbx-contact-confirm-panel',
246 'frame_panel_attrs' =>
'',
247 'frame_subbar' =>
'',
248 'frame_form_open' =>
'',
249 'frame_form_close' =>
'',
250 'frame_body_class' =>
'',
251 'frame_body_head' =>
'',
252 'frame_body_tail' =>
'',
253 'bar_class' =>
'dbx-module-bar',
254 'bar_title_class' =>
'dbx-module-bar-titleblock',
255 'bar_actions_class' =>
'dbx-module-bar-actions',
256 'bar_title' =>
$form->get_fd_message(
'confirm_title'),
257 'bar_icon' =>
'bi-check2-circle',
258 'bar_subtitle' =>
$form->get_fd_message(
261 'bar_title_pre' =>
'',
262 'bar_title_heading_attrs' =>
'',
265 'bar_actions' =>
$tpl->get_tpl(
'dbxContact|contact-confirm-bar-actions', array(
266 'my_requests' => $this->my_requests_button(),
270 return str_replace(
'[dbx:js]',
'',
$html);
274 $oForm =
dbx()->get_system_obj(
'dbxForm');
275 $oDB =
dbx()->get_system_obj(
'dbxDB');
276 $successContent =
'';
278 $oForm->init(
'dbxContact_form',
'contact-form');
279 $oForm->set_editor_class_file(__FILE__);
281 $oForm->_fd =
'dbxContact|contact-form';
282 $oForm->load_fd_messages();
283 $oForm->_action =
'?dbx_modul=dbxContact&dbx_run1=form';
284 $oForm->add_module_bar(
285 $oForm->get_fd_message(
'bar_title'),
287 $oForm->get_fd_message(
'bar_subtitle')
289 $oForm->add_rep(
'bar_class',
'dbx-module-bar');
290 $oForm->add_rep(
'frame_panel_class',
'dbxForm_wrapper dbx-contact');
291 $oForm->prepare_form_shell(array(
'class' =>
'dbx-contact-form'));
292 $oForm->add_rep(
'bar_actions',
'{obj:contact_bar_actions}');
293 $oForm->add_obj(
'contact_bar_actions',
'dbxContact|contact-form-bar-actions', array(
294 'bar_form_id' =>
'dbx_form_' . (
int) $oForm->_next_i,
296 $oForm->_data = $this->current_user_defaults();
297 $oForm->set_msg_info(
'');
298 $oForm->set_msg_ok($oForm->get_fd_message(
'request_success'));
299 $oForm->set_msg_error($oForm->get_fd_message(
'validation_error'));
300 $oForm->set_msg_warning($oForm->get_fd_message(
'form_warning'));
301 $oForm->_try_reset = 6;
302 $oForm->_try_max = 5;
303 $oForm->_try_msg = $oForm->get_fd_message(
'try_limit');
305 $oForm->add_fld(
'name');
306 $oForm->add_fld(
'email');
307 $oForm->add_fld(
'phone');
308 $oForm->add_fld(
'subject');
309 $oForm->add_fld(
'message');
311 $oForm->add_obj(
'my_requests',
'dbxContact|contact-my-requests-button');
313 $oForm->add_obj(
'my_requests',
'obj-value',
'');
316 if ($oForm->submit()) {
317 if (!$oForm->errors()) {
318 $submitData = $this->snapshot_submitted_data($oForm);
319 $spamReason = $this->spam_reason($submitData);
320 if ($spamReason !==
'') {
321 $oForm->set_msg_error(
322 $oForm->get_fd_message(
'spam_error')
324 $oForm->add_fld_error(
326 $oForm->get_fd_message(
'spam_field_error')
328 dbx()->sys_msg(
'security',
'dbxContact',
'spam_guard',
'Kontaktanfrage blockiert', $spamReason .
' email=' . ($submitData[
'email'] ??
''));
332 if (!$oForm->errors()) {
333 $submitData = $this->snapshot_submitted_data($oForm);
337 'request_ip' => substr((
string) (
$_SERVER[
'REMOTE_ADDR'] ??
''), 0, 64),
338 'request_user_agent' => substr((
string) (
$_SERVER[
'HTTP_USER_AGENT'] ??
''), 0, 512),
340 'mail_sent_date' =>
'',
341 'confirm_mail_sent' => 0,
342 'confirm_mail_sent_date' =>
'',
345 $ok = $oForm->save_post($this->dd, 0, $extra);
346 $rid = (int) $oForm->_rid;
348 if (!
$ok || $rid <= 0) {
349 $oForm->_msg_error = $oForm->get_fd_message(
354 $record = $oDB->select1($this->dd, $rid,
'*', 0);
355 if (is_array($record)) {
356 foreach (array(
'name',
'email',
'phone',
'subject',
'message') as
$field) {
357 if (trim((
string) ($data[
$field] ??
'')) ===
'' && trim((
string) ($record[
$field] ??
'')) !==
'') {
362 $confirmMailOk =
null;
365 'author_uid' => (
int)
dbx()->
user(),
366 'author_type' =>
'requester',
367 'message_type' =>
'request',
368 'visibility' =>
'public',
369 'body' => (
string) ($data[
'message'] ??
''),
370 'status_to' =>
'open',
373 'priority' =>
'normal',
378 $adminMailOk = (bool) $this->mail_request($data, $rid);
380 $oDB->update($this->dd, array(
382 'mail_sent_date' => date(
'Y-m-d H:i:s'),
383 ), $rid, 0, 1, 1, 1);
385 $oForm->set_msg_error(
386 $oForm->get_fd_message(
'admin_mail_error')
388 $oForm->add_fld_error(
390 $oForm->get_fd_message(
'email_field_error')
396 $confirmMailOk = (bool) $this->mail_confirm($data, $rid);
397 if ($confirmMailOk) {
398 $oDB->update($this->dd, array(
399 'confirm_mail_sent' => 1,
400 'confirm_mail_sent_date' => date(
'Y-m-d H:i:s'),
401 ), $rid, 0, 1, 1, 1);
403 $oForm->set_msg_error(
404 $oForm->get_fd_message(
'confirm_mail_error')
406 $oForm->add_fld_error(
408 $oForm->get_fd_message(
409 'confirm_email_field_error'
415 if (!$oForm->errors()) {
416 $successContent = $this->render_confirm(
427 if ($successContent !==
'') {
428 return $successContent;
431 return $oForm->run();