-
Notifications
You must be signed in to change notification settings - Fork 1
/
message.php
222 lines (213 loc) · 8.09 KB
/
message.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
<?php
/**
* Send a message to a user in the system
*
* Genmod: Genealogy Viewer
* Copyright (C) 2005 - 2012 Genmod Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* @package Genmod
* @subpackage Admin
* @version $Id: message.php 29 2022-07-17 13:18:20Z Boudewijn $
*/
/**
* Inclusion of the configuration file
*/
require("config.php");
if (!isset($action)) $action="compose";
PrintSimpleHeader(GM_LANG_Genmod_message);
if (!isset($subject)) $subject = "";
if (!isset($url)) $url = "";
if (!isset($method)) $method="messaging2";
if (isset($body)) $body = stripslashes($body);
else $body = "";
if (!isset($from_name)) $from_name="";
if (!isset($from_email)) $from_email="";
$message = "";
if (empty($to)) {
print "<span class=\"Error\">".GM_LANG_no_to_user."</span><br />";
PrintSimpleFooter();
exit;
}
if ($to=="all" && !$gm_user->userIsAdmin()) {
print "<span class=\"Error\">".GM_LANG_no_to_user."</span><br />";
PrintSimpleFooter();
exit;
}
// NOTE: $_SESSION["good_to_send"] is used for preventing sending a message more than once
if (($action=="send")&&(isset($_SESSION["good_to_send"]))&&($_SESSION["good_to_send"]===true)) {
$_SESSION["good_to_send"] = false;
if (!empty($from_email)) $from = $from_email;
$tuser =& User::GetInstance($from);
if ($tuser->is_empty) {
if (!CheckEmailAddress($from)) {
$message = GM_LANG_invalid_email;
$action="compose";
}
}
//-- check referer for possible spam attack
if (!isset($_SERVER['HTTP_REFERER']) || stristr($_SERVER['HTTP_REFERER'],"message.php")===false) {
$message = "Invalid page referer";
WriteToLog('Message-> Invalid page referer while trying to send a message. Possible spam attack.', 'W', 'S');
$action="compose";
}
if ($action != "compose") {
$toarray = array();
$toarray[] = $to;
if ($to == "all") {
$toarray = array();
$users = UserController::GetUsers();
foreach($users as $indexval => $tuser) {
if ($tuser->username != $gm_user->username) $toarray[] = $tuser->username;
}
}
if ($to == "never_logged") {
$toarray = array();
$users = UserController::GetUsers();
foreach($users as $indexval => $tuser) {
if ($tuser->reg_timestamp > $tuser->sessiontime) {
$toarray[] = $tuser->username;
}
}
}
if ($to == "last_6mo") {
$toarray = array();
$users = UserController::GetUsers();
$sixmos = 60*60*24*30*6; //-- timestamp for six months
foreach($users as $indexval => $tuser) {
if (time() - $tuser->sessiontime > $sixmos) {
$toarray[] = $tuser->username;
}
}
}
$i = 0;
foreach($toarray as $indexval => $to) {
$message = null;
$message = new Message();
$message->to = $to;
$message->from = $from;
if (!empty($from_name)) {
$message->from_name = $from_name;
$message->from_email = $from_email;
}
$message->subject = $subject;
$url = preg_replace("/".session_name()."=.*/", "", $url);
$message->body = $body;
$message->created = $time;
$message->method = $method;
$message->url = $url;
if ($i>0) $message->no_from = true;
if ($message->AddMessage()) {
print GM_LANG_message_sent." - ";
$touser =& User::GetInstance($to);
if ($touser->username != $from) print $touser->firstname." ".$touser->lastname."<br />";
else print $to;
}
$i++;
}
}
}
if ($action=="compose") {
?>
<script language="JavaScript" type="text/javascript">
<!--
function validateEmail(email) {
if (typeof(email) == "undefined" || email.value.search("(.*)@(.*)")==-1) {
alert('<?php print GM_LANG_invalid_email; ?>');
email.focus();
return false;
}
return checkForm(document.messageform);
}
function checkForm(frm) {
if (typeof(frm.subject.value) == "undefined" || frm.subject.value=="") {
alert('<?php print GM_LANG_enter_subject; ?>');
frm.subject.focus();
return false;
}
if (typeof(frm.body.value) == "undefined" || frm.body.value=="") {
alert('<?php print GM_LANG_enter_body; ?>');
frm.body.focus();
return false;
}
return true;
}
//-->
</script>
<?php
$username = $gm_user->username;
print "<form name=\"messageform\" method=\"post\" action=\"message.php\" onsubmit=\"t = new Date(); document.messageform.time.value=t.toUTCString(); ";
if (empty($username)) print "return validateEmail(document.messageform.from_email);";
else print "return checkForm(document.messageform);";
print "\">\n";
print "<table class=\"NavBlockTable\">\n";
print "<tr><td class=\"NavBlockHeader\" colspan=\"2\">".GM_LANG_message;
if (!empty($message)) print "<br /><span class=\"Error\">".$message;
print "</td></tr>";
$_SESSION["good_to_send"] = true;
if (empty($username)) {
print "<tr><td class=\"NavBlockLabel\" colspan=\"2\">".GM_LANG_message_instructions."</td></tr>";
}
$touser =& User::GetInstance($to);
$lang_temp = "lang_name_".$touser->language;
if (!empty($touser->username)) {
print "<tr><td class=\"NavBlockLabel\" colspan=\"2\">".str_replace("#TO_USER#", "<b>".$touser->firstname." ".$touser->lastname."</b>", GM_LANG_sending_to)."<br />";
print str_replace("#USERLANG#", "<b>".constant("GM_LANG_".$lang_temp)."</b>", GM_LANG_preferred_lang)."</td></tr>\n";
}
if (empty($username)){
print "<tr>";
print "<td class=\"NavBlockLabel\">".GM_LANG_message_from_name."</td>";
print "<td class=\"NavBlockField\"><input type=\"text\" name=\"from_name\" size=\"40\" value=\"$from_name\" /></td>";
print "</tr>";
print "<tr>";
print "<td class=\"NavBlockLabel\">".GM_LANG_message_from."</td>";
print "<td class=\"NavBlockField\"><input type=\"text\" name=\"from_email\" size=\"40\" value=\"$from_email\" onchange=\"sndReq('mailerr', 'checkemail', true, 'email', this.value);\" /> <span id=\"mailerr\"></span><br />".GM_LANG_provide_email."</td>";
print "</tr>\n";
}
print "<tr>";
print "<td class=\"NavBlockLabel\">".GM_LANG_message_subject."</td>";
print "<td class=\"NavBlockField\">";
if (!empty($username)){
print "<input type=\"hidden\" name=\"from\" value=\"$username\"/>\n";
}
print "<input type=\"hidden\" name=\"action\" value=\"send\" />\n";
print "<input type=\"hidden\" name=\"to\" value=\"$to\" />\n";
print "<input type=\"hidden\" name=\"time\" value=\"\" />\n";
print "<input type=\"hidden\" name=\"method\" value=\"$method\" />\n";
print "<input type=\"hidden\" name=\"url\" value=\"$url\" />\n";
print "<input type=\"text\" name=\"subject\" size=\"50\" value=\"".stripslashes($subject)."\" /></td>";
print "</tr>\n";
print "<tr>";
print "<td class=\"NavBlockLabel\">".GM_LANG_message_body."</td>";
print "<td class=\"NavBlockField\"><textarea name=\"body\" cols=\"50\" rows=\"7\">$body</textarea></td>";
print "</tr>\n";
if ($method=="messaging2") {
print "<tr><td class=\"NavBlockColumnHeader AdminNavBlockColumnHeader\" colspan=\"2\">";
PrintText("messaging2_help");
print "</td></tr>";
}
print "<tr>";
print "<td class=\"NavBlockFooter\" colspan=\"2\"><input type=\"submit\" value=\"".GM_LANG_send."\" /></td>";
print "</tr>\n";
print "</table>\n";
print "</form>\n";
}
else if ($action=="delete") {
if (MessageController::deleteMessage($id)) print GM_LANG_message_deleted;
}
print "<div class=\"CloseWindow\"><a href=\"#\" onclick=\"if (window.opener.refreshpage) window.opener.refreshpage(); window.close();\">".GM_LANG_close_window."</a></div>";
PrintSimpleFooter();
?>