forked from sauruscms/Saurus-CMS-Community-Edition
-
Notifications
You must be signed in to change notification settings - Fork 1
/
form.php
233 lines (191 loc) · 7.27 KB
/
form.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
<?php
/**
* This source file is is part of Saurus CMS content management software.
* It is licensed under MPL 1.1 (http://www.opensource.org/licenses/mozilla1.1.php).
* Copyright (C) 2000-2010 Saurused Ltd (http://www.saurus.info/).
* Redistribution of this file must retain the above copyright notice.
*
* Please note that the original authors never thought this would turn out
* such a great piece of software when the work started using Perl in year 2000.
* Due to organic growth, you may find parts of the software being
* a bit (well maybe more than a bit) old fashioned and here's where you can help.
* Good luck and keep your open source minds open!
*
* @package SaurusCMS
* @copyright 2000-2010 Saurused Ltd (http://www.saurus.info/)
* @license Mozilla Public License 1.1 (http://www.opensource.org/licenses/mozilla1.1.php)
*
*/
##############################
# Processes feedback form and sends e-mail
# : is FORM action value for feedback adding forms
# : is independent script, not for including, new Site is generated
##############################
global $site;
preg_match('/\/(admin|editor)\//i', $_SERVER["REQUEST_URI"], $matches);
$class_path = $matches[1] == "editor" ? "../classes/" : "./classes/";
include($class_path."port.inc.php");
$debug = $_COOKIE["debug"] ? 1:0;
$site = new Site(array(
on_debug=>$debug
));
$errors = array();
if(!isset($_SESSION['keel']))
{
//no session started, prolly a bot, exit
header('Location: index.php');
exit;
}
if($site->CONF['feedbackform_check_for_captcha'] == 1)
{
if(isset($_SESSION['scms_captcha']) && is_array($_SESSION['scms_captcha']))
{
$captcha = array_keys($_SESSION['scms_captcha']);
$captcha['name'] = $captcha[0];
$captcha['text'] = $_SESSION['scms_captcha'][$captcha['name']];
if(strtolower($_POST['captcha_'.$captcha['name']]) == strtolower($captcha['text']))
{
$capthca_check_failed = false;
}
else
{
$capthca_check_failed = true;
}
}
else
{
$capthca_check_failed = true;
}
}
unset($_SESSION['scms_captcha']);
if($capthca_check_failed)
{
$errors[] = 'CAPTHCA';
}
$fdat = sizeof($_POST) ? $_POST : $_GET;
foreach ($fdat as $key=>$value) {
if(is_array($value)) $value = implode(', ', $value);
$site->debug->msg("$key: $value");
list($prefix, $field) = split("_",$key,2);
if (!$field) {
$field = $prefix;
$prefix = "000";
}
if (preg_match("/^_/",$field)) {
# kui välja nimi algab __ -ga,
# siis ignoreerime seda
$site->debug->msg("skipped");
next;
}
elseif ($field == 'id') {
# if fieldname is "id" => ignore it (Bug #927)
$site->debug->msg("skipped");
next;
}
else {
# ----------------------------------------
# Data check
# ----------------------------------------
$value = trim($value); //bug #2390
# ----------------------------------------
# required field
# ----------------------------------------
if(strlen($prefix) <= 3 && strpos(strtolower($prefix), array('a', 'b', 'c', 'd', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',)) === false)
{
if (preg_match("/r/i",$prefix) && $value==='') {
$site->debug->msg("error: required");
$errors[] = $field;
}
# ----------------------------------------
# email field
# ----------------------------------------
if (preg_match("/e/i",$prefix) && $value!=='' && !preg_match("/^[\w\-\&\.]+\@[\w\-\&\.]+$/i",$value)) {
$site->debug->msg("error: not a email");
$errors[] = $field;
}
# ----------------------------------------
# number with dot field
# ----------------------------------------
if (preg_match("/f/i",$prefix) && $value!=='' && !preg_match("/^[\d\.\,]+$/",$value)) {
$site->debug->msg("error: not a number");
$errors[] = $field;
}
}
else
{
$field = $key;
}
if ($field == "systemfield") {
$site->debug->msg("SYSTEM");
list($tomail,$bad_url,$ok_url,$subject) = split('\|\|\|', $value);
// bug #2388 Tagaside vormist eemaldada e-maili aadress, tagasiasendus
$result = new SQL($site->db->prepare('select mail from allowed_mails where id = ?;', $tomail));
if($result->rows == 1) $tomail = $result->fetchsingle();
$site->debug->msg("to: $tomail");
$site->debug->msg("OK: $ok_url");
$site->debug->msg("ERR: $bad_url");
} else if ($field!="keel" && $field!="op") {
$output .= preg_replace("/((re)|(er)|(rf)|(fr)|(e)|(r)|(f))_/", "", $key).": $value\n";
}
}
}
if ($subject) {
foreach ($fdat as $key=>$value) {
list($prefix, $field) = split("_",$key,2);
$subject = str_replace("[".$field."]", $value, $subject);
}
}
# ----------------------------------------
# some enviroment variables
# ----------------------------------------
#??????????????
#map {$out{$_} = $ENV{$_}} split(/ /, $$CONF{env_var});
# ----------------------------------------
# view allowed_mails table
# ----------------------------------------
# added 08.12.2003 by merle: can use multiple e-mails, separated by comma
$sql = $site->db->prepare("SELECT * FROM allowed_mails WHERE FIND_IN_SET(mail,?)",$tomail);
$sth = new SQL($sql);
$sql1 = $site->db->prepare("SELECT * FROM users WHERE FIND_IN_SET(email,?)", $tomail);
$sth1 = new SQL($sql1);
$test = $sth->rows + $sth1->rows;
if ( !$test ) { $errors[] = "Error! Receiver e-mail in mail form has been changed by unauthorized persons."; }
if (sizeof($errors)==0) {
# -------------------
# Send email message
# -------------------
#print "<pre>$output</pre>";
$output = "The following information was submitted by ".$_SERVER["REMOTE_ADDR"]."\nfrom ".$_SERVER["HTTP_REFERER"]."\non ".date("d.m.Y T")."\n\n".$output;
include_once($class_path.'mail.class.php');
$mail = new email(array(
'subject' => ($subject ? $subject : $site->CONF['subject']),
'message' => $output,
'charset' => $site->encoding,
));
$send_status = $mail->send_mail(array(
'to' => $tomail,
'from' => $site->CONF['from_email'],
));
//$send_status = mail($tomail, ($subject ? $subject : $site->CONF["subject"]), $output, "From: ".$site->CONF[from_email]."\nContent-Type: text/plain; charset=".$site->encoding);
# kui mail OK
if ($send_status) {
header("Location: ".(empty($_SERVER['HTTPS']) ? 'http://': 'https://').$site->CONF[hostname].$site->CONF[wwwroot].($site->in_editor ? "/editor" : "")."/".$ok_url);
# kirjuta error logi
} else {
new Log(array(
'component' => 'Feedback forms',
'type' => 'ERROR',
'message' => "Error occurred during sending form feedback e-mail: ".$send_status." (From: ".htmlspecialchars($site->CONF[from_email])." To: ".htmlspecialchars($tomail).")",
));
$errors[] = "Error occurred during sending form feedback e-mail!";
}
}
if (sizeof($errors)) {
# -------------------
# Error handling
# -------------------
# $http_headers_out{'Location'} = "$bad_url\&errors=".join("",@errors)."\n\n" unless $fdat{debug};
# Bug #2221: [error] väljastab vigaste väljade nimed ühes jorus
header("Location: ".(empty($_SERVER['HTTPS']) ? 'http://': 'https://').$site->CONF[hostname].$site->CONF[wwwroot].($site->in_editor ? "/editor" : "")."/".$bad_url."&op=error&fields=".join(",",$errors));
}
$site->debug->print_msg();