-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathevalform.php
1398 lines (1300 loc) · 69.2 KB
/
evalform.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* WebsiteBaker CMS module: mpForm
* ===============================
* This module allows you to create customised online forms, such as a feedback form with file upload and customizable email notifications. mpForm allows forms over one or more pages, loops of forms, conditionally displayed sections within a single page, and many more things. User input for the same session_id will become a single row in the submitted table. Since Version 1.1.0 many ajax helpers enable you to speed up the process of creating forms with this module. Since 1.2.0 forms can be imported and exported directly in the module.
*
* @category page
* @module mpform
* @version 1.3.36
* @authors Frank Heyne, NorHei(heimsath.org), Christian M. Stefan (Stefek), Martin Hecht (mrbaseman) and others
* @copyright (c) 2009 - 2020, Website Baker Org. e.V.
* @url https://github.com/WebsiteBaker-modules/mpform
* @license GNU General Public License
* @platform 2.8.x
* @requirements php >= 5.3
*
**/
/* This file evaluates the submitted form in the frontend. */
// Must include code to stop this file being access directly
if(defined('WB_PATH') == false) { exit("Cannot access this file directly"); }
// obtain module directory
$mod_dir = basename(dirname(__FILE__));
// include the wrapper for escaping sql queries in old php / WB versions
require_once(WB_PATH.'/modules/'.$mod_dir.'/functions.php');
require_once(dirname(__FILE__).'/constants.php');
if (!function_exists('mpform_upload_one_file')) {
function mpform_upload_one_file($fieldid, $fileid, $upload_files_folder,
$filename, $only_exts, $chmod, $maxbytes) {
// include strings for this function
$mod_dir = basename(dirname(__FILE__));
@include(get_module_language_file($mod_dir));
// stop if file too large
if ($_FILES[$fieldid]['size'][$fileid] > $maxbytes) {
$s = sprintf(
$LANG['frontend']['err_too_large'],
$_FILES[$fieldid][$fileid]['size'],
$maxbytes
);
return $s;
}
// stop after upload error
if ($_FILES[$fieldid]['error'][$fileid] == 1) {
$s = sprintf($LANG['frontend']['err_too_large2'], $maxbytes);
return $s;
} elseif ($_FILES[$fieldid]['error'][$fileid] == 2) {
$s = sprintf($LANG['frontend']['err_too_large2'], $maxbytes);
return $s;
} elseif ($_FILES[$fieldid]['error'][$fileid] == 3) {
$s = $LANG['frontend']['err_partial_upload'];
return $s;
} elseif ($_FILES[$fieldid]['error'][$fileid] == 4) {
$s = $LANG['frontend']['err_no_upload'];
return $s;
}
$cwd = dirname(__FILE__);
$old_path = ini_get("include_path");
ini_set("include_path", $old_path.((strstr($old_path,';')) ? ';' : ':').$cwd."/pear/HTTP");
require_once "Upload.php";
$lang = DEFAULT_LANGUAGE;
$upload = new http_upload(strtolower($lang));
if ($chmod) $upload->setChmod(intval($chmod, 8));
$file = $upload->getFiles($fileid, true);
if ($upload->isError($file)) return $file->getMessage();
if (trim($only_exts)) {
$a = explode(",",$only_exts);
$file->setValidExtensions($a,'accept');
} else {
$a = array('NOT_POSSIBLE_ONE');
$file->setValidExtensions($a,'deny');
}
if (!$file->isMissing()) {
if ($file->isValid()) {
$file->setName($filename);
$dest_name = $file->moveTo($upload_files_folder);
if ($upload->isError($dest_name)) return $dest_name->getMessage();
} elseif ($file->isError()) return $file->errorMsg();
} else {
return "$fileid - missing... ".$file->errorMsg();
}
return false; // upload did not(!) fail - so error string is boolean false
}
}
if (!function_exists('NewWbMailer')) {
function NewWbMailer()
{
if (class_exists('Mailer', true)) {
// for WBCE > 1.3.3 (?)
return new Mailer();
}
if (!class_exists('WbMailer', false)) {
// its wb < 2.8.3 sp4(?)
if (!class_exists('wbmailer', false)) {
include_once(WB_PATH.'/include/phpmailer/class.phpmailer.php');
include_once(WB_PATH.'/framework/class.wbmailer.php');
}
return new wbmailer();
} else {
return new WbMailer();
}
}
}
if (!function_exists('mpform_mailx')) {
// Validate send email
function mpform_mailx($fromaddress, $replytoaddress, $toaddress, $subject,
$message, $email_css, $fromname='', $file_attached='') {
$fromaddress = preg_replace('/[\r\n]/', '', $fromaddress);
$subject = preg_replace('/[\r\n]/', '', $subject);
$htmlmessage = preg_replace('/[\r\n]/', "<br />\n", $message);
$plaintext = preg_replace(",<br />,", "\r\n", $message);
$plaintext = preg_replace(",</h.>,", "\r\n", $plaintext);
$plaintext = htmlspecialchars_decode(preg_replace(",<[^>]+>,", " ", $plaintext), ENT_NOQUOTES);
// create PHPMailer object and define default settings
$myMail = NewWbMailer();
if(defined('DEBUG') && DEBUG){
$myMail->set('SMTPDebug', 2); // Enable verbose debug output
$myMail->set('Debugoutput', 'error_log');
}
// set user defined from address
if ($fromaddress!='') {
if($fromname!='') $myMail->FromName = $fromname; // FROM-NAME
if ($fromaddress == 'SERVER_EMAIL') {
if(defined('SERVER_EMAIL')) {
$fromaddress = SERVER_EMAIL;
} else {
$fromaddress = '';
}
}
$myMail->From = $fromaddress; // FROM:
}
// set user defined replyto address
if ($replytoaddress!='') {
if ($replytoaddress == 'SERVER_EMAIL') {
if(defined('SERVER_EMAIL')) {
$replytoaddress = SERVER_EMAIL;
} else {
$replytoaddress = '';
}
}
$myMail->AddReplyTo($replytoaddress); // REPLY TO:
} else {
$myMail->AddReplyTo($fromaddress); // REPLY TO:
}
// define recipient(s)
$emails = explode(",", $toaddress);
foreach ($emails as $recip) {
if(defined('SERVER_EMAIL')) {
$recip = str_replace('SERVER_EMAIL', SERVER_EMAIL, $recip);
} else {
$recip = str_replace('SERVER_EMAIL', '', $recip);
}
if (trim($recip) != '') {
if (preg_match("/^bcc\:(.*?)\<(.*?)\>$/i",trim($recip),$matches)) { //bcc whith name
$myMail->AddBcc(trim($matches[2]), trim($matches[1]));
continue;
}
if (preg_match("/^cc\:(.*?)\<(.*?)\>$/i",trim($recip),$matches)) { //cc whith name
$myMail->AddCc(trim($matches[2]), trim($matches[1]));
continue;
}
if (preg_match("/^(.*?)\<(.*?)\>$/i",trim($recip),$matches)) { // address whith name
$myMail->AddAddress(trim($matches[2]), trim($matches[1]));
continue;
}
if (strpos( $recip, "BCC:")===0) {$myMail->AddBcc(trim(substr($recip, 4)));} // BCC:
elseif (strpos($recip, "CC:")===0) {$myMail->AddCc(trim(substr($recip, 3)));} // CC:
else {$myMail->AddAddress(trim($recip)); } // TO:
}
}
// define information to send out
$myMail->Subject = $subject; // SUBJECT
$myMail->Body = '<html><head><style>'.$email_css.'</style></head><body>'
. $htmlmessage.'</body></html>'; // CONTENT (HTML)
$myMail->AltBody = $plaintext; // CONTENT (PLAINTEXT)
if (is_array($file_attached)) {
foreach($file_attached as $k => $v) {
$myMail->AddAttachment($k, $v); // ATTACHMENT (FILE)
}
}
// check if there are any send mail errors, otherwise say successful
if (!$myMail->Send()) {
return false;
} else {
return true;
}
}
}
////////////////// Main function ///////////////////////
if (!function_exists('eval_form')) {
function eval_form($section_id) {
global $database, $MESSAGE, $admin, $TEXT, $LANG;
(preg_match("/^\d+\.\d+\.\d+\.\d+$/", $_SERVER['REMOTE_ADDR']))
? $ip = $_SERVER['REMOTE_ADDR']
: $ip = 'unknown'; // IP address of sender
if(class_exists('Settings') && defined('WBCE_VERSION')){
$filter_settings = array(
'sys_rel' => Settings::Get("opf_sys_rel", 0),
'email_filter' => Settings::Get("opf_email_filter", 0),
'mailto_filter' => Settings::Get("opf_mailto_filter", 1),
'at_replacement' => Settings::Get('opf_at_replacement', '(at)') ,
'dot_replacement' => Settings::Get('opf_dot_replacement', '(dot)')
);
}
else if (file_exists(WB_PATH.'/modules/output_filter/filter-routines.php')) {
if(!function_exists('executeFrontendOutputFilter')) {
include(WB_PATH.'/modules/output_filter/filter-routines.php');
}
if (function_exists('get_output_filter_settings')) {
$filter_settings = get_output_filter_settings();
} elseif (function_exists("getOutputFilterSettings")) {
$filter_settings = getOutputFilterSettings();
}else {
$filter_settings['email_filter'] = 0;
}
}
else {
// no output filter used, define default settings
$filter_settings['email_filter'] = 0;
}
$files_to_attach = array();
$upload_filename = '';
if(ENABLED_ASP AND (!(defined('MPFORM_SKIP_ASP')&&(MPFORM_SKIP_ASP))) AND (
// form faked? Check the honeypot-fields.
( !isset($_POST['submitted_when'.$section_id])
OR !isset($_SESSION['submitted_when'.$section_id]))
OR ($_POST['submitted_when'.$section_id] != $_SESSION['submitted_when'.$section_id])
OR (!isset($_POST['email']) OR $_POST['email'])
OR (!isset($_POST['homepage']) OR $_POST['homepage'])
OR (!isset($_POST['comment']) OR $_POST['comment'])
OR (!isset($_POST['url']) OR $_POST['url'])
)) {
$sUrlToGo = WB_URL.PAGES_DIRECTORY;
if(headers_sent())
$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS']
.' (ID_CHECK) '.__FILE__.':'.__LINE__,
$sUrlToGo);
else
header("Location: ". $sUrlToGo);
exit(0);
}
// Get form settings
$query_settings
= $database->query(
"SELECT *"
. " FROM ".TP_MPFORM."settings"
. " WHERE section_id = '$section_id'"
);
if($query_settings->numRows() > 0) {
$fetch_settings = $query_settings->fetchRow();
$is_following = $fetch_settings['is_following'];
// Check that submission ID matches
if ((!isset($_SESSION['submission_id_'.$section_id])
OR !isset($_POST['submission_id'])
OR $_SESSION['submission_id_'.$section_id] != $_POST['submission_id'])
AND (!(defined('MPFORM_SKIP_SUBMISSION_ID')&&(MPFORM_SKIP_SUBMISSION_ID)))) {
if ($is_following) {
$sUrlToGo = WB_URL.PAGES_DIRECTORY;
if(headers_sent())
$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS']
.' (SUBMISSION_ID_CHECK) '.__FILE__.':'.__LINE__,
$sUrlToGo);
else
header("Location: ". $sUrlToGo);
exit(0);
}
include_once(WB_PATH .'/modules/mpform/paintform.php');
paint_form($section_id);
return;
}
$email_from = $fetch_settings['email_from'];
if(substr($email_from, 0, 5) == 'field') {
// Set the email from field to what the user entered in the specified field
$email_from = htmlspecialchars($admin->add_slashes($_POST[$email_from]));
}
if ($email_from == 'wbu') {
$email_from = $admin->get_email();
}
if ($email_from == 'SERVER_EMAIL') {
if(defined('SERVER_EMAIL')) {
$email_from = SERVER_EMAIL;
} else {
$email_from = '';
}
}
$email_replyto = $fetch_settings['email_replyto'];
if(substr($email_replyto, 0, 5) == 'field') {
// Set the email replyto field to what the user entered in the specified field
$email_replyto
= htmlspecialchars(
$admin->add_slashes($_POST[$email_replyto])
);
}
if ($email_replyto == 'wbu') {
$email_replyto = $admin->get_email();
}
if ($email_replyto == 'SERVER_EMAIL') {
if(defined('SERVER_EMAIL')) {
$email_replyto = SERVER_EMAIL;
} else {
$email_replyto = '';
}
}
$email_fromname = $fetch_settings['email_fromname'];
if(substr($email_fromname, 0, 5) == 'field') {
// Set the email from field to what the user entered in the specified fields
$email_fromname = explode (",", $email_fromname);
$fromnames = array();
foreach($email_fromname as $fromname){
$fromnames[]
= htmlspecialchars(
$admin->get_post_escaped($fromname),
ENT_QUOTES
);
}
$email_fromname = implode(' ', $fromnames);
}
if ($email_fromname == 'wbu') {
$email_fromname = $admin->get_display_name();
}
$success_email_to = $fetch_settings['success_email_to'];
if(substr($success_email_to, 0, 5) == 'field') {
// Set the success_email to field to what the user entered in the specified field
$success_email_to
= htmlspecialchars(
$admin->add_slashes($_POST[$success_email_to])
);
}
if ($success_email_to == 'wbu') {
$success_email_to = $admin->get_email();
}
if ($success_email_to == 'SERVER_EMAIL') {
if(defined('SERVER_EMAIL')) {
$success_email_to = SERVER_EMAIL;
} else {
$success_email_to = '';
}
}
$email_subject = $fetch_settings['email_subject'];
$email_text = $fetch_settings['email_text'];
$email_css = $fetch_settings['email_css'];
$success_page = $fetch_settings['success_page'];
$success_text = $fetch_settings['success_text'];
$submissions_text = $fetch_settings['submissions_text'];
$success_email_from = $fetch_settings['success_email_from'];
if(substr($success_email_from, 0, 5) == 'field') {
// Set the email from field to what the user selected in the specified field
$success_email_from = $admin->add_slashes($_POST[$success_email_from]);
if(is_array($success_email_from))$success_email_from = $success_email_from[0];
$success_email_from = htmlspecialchars($success_email_from);
}
if ($success_email_from == 'wbu') {
$success_email_from = $admin->get_email();
}
if ($success_email_from == 'SERVER_EMAIL') {
if(defined('SERVER_EMAIL')) {
$success_email_from = SERVER_EMAIL;
} else {
$success_email_from = '';
}
}
$success_email_fromname = $fetch_settings['success_email_fromname'];
if(substr($success_email_fromname, 0, 5) == 'field') {
// Set the name from field to what the user selected in the specified field
$success_email_fromname = $admin->add_slashes($_POST[$success_email_fromname]);
if(is_array($success_email_fromname))$success_email_fromname = $success_email_fromname[0];
$success_email_fromname = htmlspecialchars($success_email_fromname);
}
if ($success_email_fromname == 'wbu') {
$success_email_fromname = $admin->get_display_name();
}
$success_email_text = $fetch_settings['success_email_text'];
$success_email_css = $fetch_settings['success_email_css'];
$success_email_subject = $fetch_settings['success_email_subject'];
$max_submissions = $fetch_settings['max_submissions'];
$stored_submissions = $fetch_settings['stored_submissions'];
$use_captcha = $fetch_settings['use_captcha'];
$upload_files_folder = $fetch_settings['upload_files_folder'];
$attach_file = $fetch_settings['attach_file'];
$multiple_files = $fetch_settings['multiple_files'];
$upload_only_exts = $fetch_settings['upload_only_exts'];
$upload_file_mask = $fetch_settings['upload_file_mask'];
$max_file_size = $fetch_settings['max_file_size_kb'] * 1024;
$_POST['MAX_FILE_SIZE'] = $max_file_size; // stupid enough, PEAR checks this POST variable for maximum size!
$suffix = $fetch_settings['tbl_suffix'];
$email_to = $fetch_settings['email_to'];
// settings for html output of form input:
$heading_html = $fetch_settings['heading_html'];
$short_html = $fetch_settings['short_html'];
$long_html = $fetch_settings['long_html'];
$email_html = $fetch_settings['email_html'];
$uploadfile_html = $fetch_settings['uploadfile_html'];
} else {
exit($TEXT['UNDER_CONSTRUCTION']);
}
// get authenticated user data
if(isset($admin) AND $admin->is_authenticated() AND $admin->get_user_id() > 0) {
$submitted_by = $admin->get_user_id();
$wb_user = $admin->get_display_name();
$wb_email = $admin->get_email();
} else {
$submitted_by = 0;
$wb_user = '';
$wb_email = '';
}
$fer = array();
$err_txt = array();
$html_data_user = '';
$html_data_site = '';
$iSID = $_SESSION['submission_id_'.$section_id];
if(isset($_SESSION['html_data_user'.$iSID])) $html_data_user = $_SESSION['html_data_user'.$iSID];
if(isset($_SESSION['html_data_site'.$iSID])) $html_data_site = $_SESSION['html_data_site'.$iSID];
$format = DEFAULT_DATE_FORMAT. " " .DEFAULT_TIME_FORMAT;
$now = date($format, time()+DEFAULT_TIMEZONE);
// Captcha
$captcha_value = "";
if(isset($_POST['captcha']) AND $_POST['captcha'] != '') $captcha_value = $_POST['captcha'];
if(isset($_POST['captcha'.$section_id]) AND $_POST['captcha'.$section_id] != '') $captcha_value = $_POST['captcha'.$section_id];
if($use_captcha AND (!(defined('MPFORM_SKIP_CAPTCHA')&&(MPFORM_SKIP_CAPTCHA))) ) {
if($captcha_value!=""){
if((isset($_SESSION['captcha'.$section_id])
AND ($captcha_value != $_SESSION['captcha'.$section_id]))
OR (!isset($_SESSION['captcha'.$section_id])
AND ($captcha_value != $_SESSION['captcha']))) {
$err_txt['captcha'.$section_id]
= $LANG['frontend']['INCORRECT_CAPTCHA'];
$fer[] = 'captcha'.$section_id;
}
} else {
$err_txt['captcha'.$section_id] = $LANG['frontend']['INCORRECT_CAPTCHA'];
$fer[] = 'captcha'.$section_id;
}
}
if(isset($_SESSION['captcha'.$section_id])) {
unset($_SESSION['captcha'.$section_id]);
}
// Create blank "required" array
$mpform_fields = array(); // for results table
$mailto = "";
// Get list of fields
$query_fields = $database->query(
"SELECT *"
. " FROM ".TP_MPFORM."fields"
. " WHERE section_id = '$section_id'"
. " ORDER BY position ASC"
);
if($query_fields->numRows() > 0) {
while($field = $query_fields->fetchRow()) {
// Loop through fields and add to message body
$field_id = $field['field_id'];
$curr_field = '';
$post_field = '';
if($field['type'] != '') {
if ((!empty($_POST['field'.$field_id]))
or ($admin->get_post('field'.$field_id) == "0")) { // added Apr 2009
$post_field = $_POST['field'.$field_id];
// copy user entered data to $_SESSION in case form must be
// reviewed (for instance because of missing required values)
if (is_array($post_field)) {
$_SESSION['mpf']['field'.$field_id]
= str_replace(
array("[[", "]]"),
array("[[", "]]"),
$post_field
);
} else {
// make sure user does see what he entered:
$_SESSION['mpf']['field'.$field_id]
= str_replace(
array("[[", "]]"),
array("[[", "]]"),
htmlspecialchars(
stripslashes($post_field), ENT_QUOTES)
);
}
// no injections, please
if (!is_array($post_field)) {
$field_value
= str_replace(
array("[[", "]]"),
array("[[", "]]"),
htmlspecialchars(
$admin->get_post_escaped(
'field'.$field_id), ENT_QUOTES
)
);
}
// if the output filter is active,
// we need to revert (dot) to . and (at) to @
// (using current filter settings)
// otherwise the entered mail will not be accepted
// and the recipient would see (dot), (at) etc.
if ($filter_settings['email_filter']) {
$field_value = $post_field;
$field_value
= str_replace(
$filter_settings['at_replacement'],
'@',
$field_value
);
$field_value
= str_replace(
$filter_settings['dot_replacement'],
'.',
$field_value
);
$post_field = $field_value;
}
$aReplacements = array();
// put the template in the first index of the replacements
$aReplacements['{TEMPLATE}'] = $field['template'];
$aReplacements['{TEMPLATE0}']
= preg_replace(array("/\n/","/\r/"),'',$field['template']);
$tmp_tpl = explode("\n", $field['template']);
for($tpl_idx = 1; $tpl_idx < 10; $tpl_idx++){
$aReplacements['{TEMPLATE'.$tpl_idx.'}'] = "";
}
$tpl_idx=1;
foreach ($tmp_tpl as $curr_idx){
$aReplacements['{TEMPLATE'.$tpl_idx.'}'] = trim($curr_idx);
$tpl_idx++;
}
// Set field values for css formatting
$extraclasses = $field['extraclasses'];
if(! (preg_match('/{FORMATTED_FIELD}/',$fetch_settings['field_loop']) ||
( preg_match('/{TEMPLATE/',$fetch_settings['field_loop'])
&& preg_match('/{FORMATTED_FIELD}/',$field['template'])) ))
$extraclasses = '';
if($extraclasses!='') $extraclasses.=' ';
$classes = 'fid'.$field_id.' '.MPFORM_CLASS_PREFIX. $field['type'];
$field_classes = $extraclasses
.MPFORM_CLASS_PREFIX.'field_'.$field_id.' '
.MPFORM_CLASS_PREFIX.'field_'.$field['type'];
$aReplacements['{CLASSES}'] = $field_classes;
if($field['type'] == 'email'){
if ($admin->validate_email($post_field) == false) {
$err_txt[$field_id] = $MESSAGE['USERS_INVALID_EMAIL'];
$fer[] = $field_id;
} else $curr_field = "'".mpform_escape_string($post_field)."'";
}
// check invalid user input
if($field['type'] == 'integer_number') {
$v = $post_field;
if (!preg_match("/^[0-9]+$/", $v)) {
// only allow valid chars
$err_txt[$field_id] = $LANG['frontend']['integer_error'];
$fer[]=$field_id;
}
}
if ($field['type'] == 'decimal_number') {
$v = $post_field;
if (!preg_match("/^(\+|\-)?[0-9]+(\,|\.)?[0-9]*$/", $v)) {
// only allow valid chars
$err_txt[$field_id] = $LANG['frontend']['decimal_error'];
$fer[]=$field_id;
}
}
if ($field['type'] == 'heading') {
$aReplacements['{HEADING}'] = $field['title'];
if(($field['value'] == '') or (preg_match('/user/',$field['value'])))
$html_data_user
.= str_replace(
array_keys($aReplacements),
array_values($aReplacements),
$heading_html
);
if(($field['value'] == '') or (preg_match('/site/',$field['value'])))
$html_data_site
.= str_replace(
array_keys($aReplacements),
array_values($aReplacements),
$heading_html
);
} elseif ($field['type'] == 'email_recip') {
// the browser will convert umlauts,
// we need to undo this for compare:
$recip = htmlentities ($post_field[0], ENT_NOQUOTES, 'UTF-8');
if ($recip == $LANG['frontend']['select']) {
$err_txt[$field_id] = $LANG['frontend']['select_recip'];
$fer[]=$field_id;
}
$recip = htmlspecialchars($post_field[0], ENT_QUOTES);
$aReplacements['{TITLE}'] = $field['title'];
$aReplacements['{DATA}'] = $recip;
$html_data_user
.= str_replace(
array_keys($aReplacements),
array_values($aReplacements),
$short_html
);
$html_data_site
.= str_replace(
array_keys($aReplacements),
array_values($aReplacements),
$short_html
);
if ($mailto == "") {
$mailto = $recip;
}
$curr_field = "'".mpform_escape_string($mailto)."'";
} elseif ($field['type'] == 'email_subj') {
$email_subject .= " ". $field_value;
$success_email_subject .= " ". $field_value;
$aReplacements['{TITLE}'] = $field['title'];
$aReplacements['{DATA}'] = $field_value;
$html_data_user
.= str_replace(
array_keys($aReplacements),
array_values($aReplacements),
$short_html
);
$html_data_site
.= str_replace(
array_keys($aReplacements),
array_values($aReplacements),
$short_html
);
$curr_field = "'".mpform_escape_string($field_value)."'";
} elseif (!is_array($post_field)) {
if ($field['type'] == 'email') {
$aReplacements['{TITLE}'] = $field['title'];
$aReplacements['{DATA}'] = $field_value;
$html_data_user
.= str_replace(
array_keys($aReplacements),
array_values($aReplacements),
$email_html
);
$html_data_site
.= str_replace(
array_keys($aReplacements),
array_values($aReplacements),
$email_html
);
} elseif ($field['type'] == 'textarea') {
// Test for duplicate (msdos-like) LF
$lines = str_replace("\r\n", "<br />", $field_value);
$aReplacements['{TITLE}'] = $field['title'];
$aReplacements['{DATA}'] = $lines;
$html_data_user
.= str_replace(
array_keys($aReplacements),
array_values($aReplacements),
$long_html
);
$html_data_site
.= str_replace(
array_keys($aReplacements),
array_values($aReplacements),
$long_html
);
} else {
$aReplacements['{TITLE}'] = $field['title'];
$aReplacements['{DATA}'] = $field_value;
$html_data_user
.= str_replace(
array_keys($aReplacements),
array_values($aReplacements),
$short_html
);
$html_data_site
.= str_replace(
array_keys($aReplacements),
array_values($aReplacements),
$short_html
);
}
$curr_field
= "'"
. mpform_escape_string(htmlspecialchars($post_field))
. "'";
} else {
$curr_field = "'";
$lines = '';
foreach ($post_field as $k => $v) {
$field_value
= htmlspecialchars(
$admin->add_slashes($v), ENT_QUOTES
);
$curr_field .= mpform_escape_string($field_value) . ", ";
$lines .= mpform_escape_string($field_value) . "<br />";
}
$curr_field = substr($curr_field, 0, -2);
$curr_field .= "'";
$aReplacements['{TITLE}'] = $field['title'];
$aReplacements['{DATA}'] = $lines;
$html_data_user
.= str_replace(
array_keys($aReplacements),
array_values($aReplacements),
$long_html
);
$html_data_site
.= str_replace(
array_keys($aReplacements),
array_values($aReplacements),
$long_html
);
}
} elseif($field['type'] == 'filename') {
$err_txt[$field_id] = "";
$tmp_html_user = "";
$tmp_html_site = "";
$tmp_filenames = "";
$tmp_files_to_attach = array();
// locally we use a copy of max_file_size
$tmp_max_file_size = $max_file_size;
$file_counter=0;
if (($field['required'] & 4) == 0){ // skip disabled fields
$tmp_files = array();
// convert single value upload to array:
if (isset($_FILES['field'.$field_id]) && !is_array($_FILES['field'.$field_id]['name']))
$tmp_files = array($_FILES['field'.$field_id]['name']);
if (isset($_FILES['field'.$field_id]) && is_array($_FILES['field'.$field_id]['name']))
$tmp_files = $_FILES['field'.$field_id]['name'];
if (count($tmp_files)){
foreach($tmp_files as $f => $name) {
if($name != ""){
if($tmp_max_file_size<=0){
$err_txt[$field_id]
.= sprintf(
$LANG['frontend']['err_upload'],
$name,
sprintf(
$LANG['frontend']['err_too_large2'], 0)
);
$fer[]=$field_id;
} else {
$filename
= preg_replace(
"/[^0-9a-zA-Z_\-\.]/",
"",
basename($name)
); // only allow valid chars in filename
$file_counter++;
// prevent from upload of millions of empty files
if($file_counter>128) break;
$newfilename
= date('YmdHis')
. "-"
. rand(10000, 99999)
. "-"
. $filename;
$uploadfailed
= mpform_upload_one_file(
'field'.$field_id,
$f,
WB_PATH.$upload_files_folder,
$newfilename,
$upload_only_exts,
$upload_file_mask,
$tmp_max_file_size
);
if ($uploadfailed) {
$err_txt[$field_id]
.= sprintf(
$LANG['frontend']['err_upload'],
$filename,
$uploadfailed
);
$fer[]=$field_id;
} else {
// for results table only:
$upload_filename
= $upload_files_folder
. "/"
. $newfilename;
// for links in email to admin and backend:
$file_url
= WB_URL
. $upload_files_folder
. "/"
. $newfilename;
if ($attach_file == 1) {
$tmp_files_to_attach[
WB_PATH
. $upload_files_folder
. "/"
. $newfilename]
= $filename;
}
$curr_field
.= "'"
. $upload_filename
. "'";
$fs
= filesize(
WB_PATH
.$upload_files_folder
."/"
.$newfilename
);
// reduce maximum by already consumed space
$tmp_max_file_size -= $fs;
// convert to human readable string for
// displaying file size in KB
$fs = sprintf("%.1f", $fs / 1024);
$aReplacements['{TITLE}'] = $field['title'];
$aReplacements['{DATA}'] = "$filename ($fs KB)";
$tmp_html_user
.= str_replace(
array_keys($aReplacements),
array_values($aReplacements),
$short_html
);
$aReplacements['{DATA}'] = $file_url;
$aReplacements['{SIZE}'] = $fs;
$tmp_html_site
.= str_replace(
array_keys($aReplacements),
array_values($aReplacements),
$uploadfile_html
);
$tmp_filenames .= "$filename ($fs KB) ";
}
}
}
if((!$multiple_files)&&($file_counter>0)) break;
}}
if($file_counter>0){
$curr_field = str_replace("''", ",", $curr_field);
$_SESSION['mpf']['datafield'.$field_id]
= array(
'user' => $tmp_html_user,
'site' => $tmp_html_site,
'files' => $tmp_files_to_attach,
'filenames' => $tmp_filenames,
'field' => $curr_field
);
$html_data_user .= $tmp_html_user;
$html_data_site .= $tmp_html_site;
$files_to_attach = array_merge($files_to_attach, $tmp_files_to_attach);
}
}
if ($file_counter==0) {
if(isset($_SESSION['mpf']['datafield'.$field_id]['user']))
$html_data_user .= $_SESSION['mpf']['datafield'.$field_id]['user'];
if(isset($_SESSION['mpf']['datafield'.$field_id]['site']))
$html_data_site .= $_SESSION['mpf']['datafield'.$field_id]['site'];
if(isset($_SESSION['mpf']['datafield'.$field_id]['field']))
$curr_field .= $_SESSION['mpf']['datafield'.$field_id]['field'];
$files_to_attach = array_merge($files_to_attach, $tmp_files_to_attach);
if ( ($field['required']==1)
&& ( (!isset($_SESSION['mpf']['datafield'.$field_id]['user']))
||(!isset($_SESSION['mpf']['datafield'.$field_id]['site'])) ))
$fer[]=$field_id;
}
// assumption: $_FILES is in the same order as filenames
// in $[field] then, we can shift it so that the next time
// pear's upload class can handle the next field.
// Otherwise we always stick to the first record
array_shift($_FILES);
} elseif ($field['type'] == 'fieldset_start') {
$html_data_user
.= "<fieldset><legend>". $field['title'] ."</legend>\n";
$html_data_site
.= "<fieldset><legend>". $field['title'] ."</legend>\n";
} elseif ($field['type'] == 'fieldset_end') {
$html_data_user .= "</fieldset>\n";
$html_data_site .= "</fieldset>\n";
} elseif ($field['type'] == 'html') {
if(($field['extra'] == '') or (preg_match('/user/',$field['extra'])))
$html_data_user
.= htmlspecialchars_decode($field['value']) . "<br />\n";
if(($field['extra'] == '') or (preg_match('/site/',$field['extra'])))
$html_data_site
.= htmlspecialchars_decode($field['value']) . "<br />\n";
} elseif($field['required'] == 1) {
$fer[]=$field_id;
}
}
if ($curr_field == '') {
$curr_field = "''";
if($field['type'] == 'integer_number') $curr_field = '0';
if ($field['type'] == 'decimal_number') $curr_field = '0.0';
}
if ($curr_field == "''") {
if($field['required'] == 1) {
$fer[]=$field_id;
}
}
$mpform_fields["$field_id"] = $curr_field;
// execute private function in private.php, if available
if (function_exists('private_function_for_field')) {
$field_errmsg
= private_function_for_field(
$field_id,
$post_field
);
if(!empty($field_errmsg)){
$fer[]=$field_id;
$err_txt[$field_id] = $field_errmsg;
}
}
} // end of field loop
}
// sanitize against any javascript injection attempts
$aTags = array( 'script', 'body', 'head', 'html', 'link');
foreach($aTags as $tag){
$html_data_user = preg_replace('/<\/?'.$tag.'[^<>]*>/i',"",$html_data_user);
$html_data_site = preg_replace('/<\/?'.$tag.'[^<>]*>/i',"",$html_data_site);
}
$tmp_mpform_fields = "";
// replace place holders in subject lines and "serialize" for database statement below
foreach($mpform_fields as $mpfid => $mpfval){
if (strlen($tmp_mpform_fields) > 0) {
$tmp_mpform_fields .= ", ";
}
$tmp_mpform_fields .= "field" . $mpfid . " = " . $mpfval . " ";
$mpfval = preg_replace(array("/^'/","/'\$/"), '', $mpfval);
$email_subject = str_replace("{FIELD".$mpfid."}", $mpfval, $email_subject);
$success_email_subject = str_replace("{FIELD".$mpfid."}", $mpfval, $success_email_subject);
$email_text = str_replace("{FIELD".$mpfid."}", $mpfval, $email_text);
$success_email_text = str_replace("{FIELD".$mpfid."}", $mpfval, $success_email_text);
}
$mpform_fields = $tmp_mpform_fields;
// Check if the user forgot to enter values into all the required fields
if(!empty($fer)) {
// paint form again:
include_once(WB_PATH .'/modules/mpform/paintform.php');
paint_form($section_id, $fer, $err_txt, false);
} else {
// Check how many times form has been submitted in last hour
$last_hour = time()-3600;
$query_submissions
= $database->query(
"SELECT submission_id"