forked from hsrai/GNDEC-SMS-Service
-
Notifications
You must be signed in to change notification settings - Fork 2
/
mailto.php
executable file
·338 lines (298 loc) · 11.3 KB
/
mailto.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
<?php
/*************************************************************
* THE ADDRESS BOOK : version 1.04d
*
*****************************************************************
* mailto.php
* Sends e-mail to one or more addresses
* Originally written by Joe Chen
*
*************************************************************/
// BUG: Mailing List displays entries without email addresses.
// ** GET CONFIGURATION DATA **
require_once('constants.inc');
require_once(FILE_FUNCTIONS);
require_once(FILE_CLASS_OPTIONS);
require_once(FILE_CLASS_CONTACTLIST);
// ** OPEN CONNECTION TO THE DATABASE **
$db_link = openDatabase($db_hostname, $db_username, $db_password, $db_name);
// ** CHECK FOR LOGIN **
// list($userGroup, $userHomeName, $userHomePage, $userCapabilities) = checkForLogin($address_session_name, CAP_MAIL);
checkForLogin('admin','user');
// ** RETRIEVE OPTIONS THAT PERTAIN TO THIS PAGE **
$options = new Options($db_link);
/*
// JOE_DEBUG: check for viewing restrictions
if ($userGroup) {
if (($list->group_id <= 2) || (!$list->group_id)) {
$r_check_GroupList = mysql_query("SELECT * FROM " . TABLE_GROUPLIST . " AS GroupList WHERE GroupName LIKE '%$userGroup%'", $db_link);
$check_GroupList = mysql_fetch_array($r_check_GroupList);
$list->group_id = $check_GroupList["GroupID"];
$list->group_name = $check_GroupList["GroupName"];
} else {
$r_check_GroupList = mysql_query("SELECT * FROM " . TABLE_GROUPLIST . " AS GroupList WHERE GroupID=$list->group_id", $db_link);
$check_GroupList = mysql_fetch_array($r_check_GroupList);
$check_GroupName = $check_GroupList["GroupName"];
if (!eregi( $userGroup, $check_GroupName)) {
echo("<P>Invalid GroupID: not allowed to view this group. ");
exit();
}
}
}
*/
// ** GET DESTINATION EMAIL ADDRESS **
// If there is an e-mail address either via POST or GET we will e-mail to that single address.
// If not, then we will default to a mailing list setup.
if ($_POST['to']) { // Look for a target e-mail in POST first, which has priority.
$mail_to = $_POST['to'];
}
elseif ($_GET['to']) { // If there is no target e-mail in POST, look in GET
$mail_to = $_GET['to'];
}
else { // If there is no target e-mail in either, then we go to default mailing list mode.
// RETRIEVE OPTIONS THAT PERTAIN TO THIS PAGE **
$options = mysql_fetch_array(mysql_query("SELECT displayAsPopup, useMailScript FROM " . TABLE_OPTIONS . " LIMIT 1", $db_link))
or die(reportScriptError("Unable to retrieve options."));
// CREATE THE LIST.
$list = &new ContactList($options->defaultLetter, $options->limitEntries);
// THIS PAGE TAKES SEVERAL GET VARIABLES
if ($_GET['groupid']) $list->group_id = $_GET['groupid'];
if ($_GET['page']) $list->current_page = $_GET['page'];
if ($_GET['letter']) $list->current_letter = $_GET['letter'];
if ($_GET['limit']) $list->max_entries = $_GET['limit'];
// Set group name (group_id defaults to 0 if not provided)
$list->group_name();
// ** RETRIEVE CONTACT LIST BY GROUP **
$r_contact = $list->retrieve();
}
// ** RETRIEVE USER CONTACT INFORMATION **
$mail_from = '';
$r_user = '[email protected]';
$mail_from = $r_user;
$SendMailButton = "Yes";
if(!$mail_from){
$mail_from = $lang['ERR_NO_EMAIL1']."<A HREF =\"".FILE_USERS."\"> ".$lang['ERR_NO_EMAIL2'];
$SendMailButton = "No";
}
?>
<HTML>
<HEAD>
<TITLE><?php echo $lang['TAB']." - ".$lang['TITLE_OPT']?></TITLE>
<LINK REL="stylesheet" HREF="styles.css" TYPE="text/css">
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
<META HTTP-EQUIV="EXPIRES" CONTENT="-1">
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo $lang['CHARSET']?>">
</HEAD>
<BODY>
<CENTER>
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=570>
<TR>
<TD CLASS="navMenu"><A HREF="javascript:history.go(-1)"><?php echo $lang['BTN_RETURN'] ?></A></TD>
</TR>
<TR>
<TD>
<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=570>
<TR VALIGN="bottom">
<TD CLASS="headTitle">
<?php // HEADER
echo (empty($mail_to) ? $lang['TOOLBOX_MAILINGLIST'] : $lang['TITLE_OPT']);
?>
</TD>
<?php // MAILING LIST
if (empty($mail_to)) {
?> <TD CLASS="headText" ALIGN="right">
<FORM NAME="selectGroup" METHOD="get" ACTION="<?php echo(FILE_MAILTO); ?>">
select group <SELECT NAME="groupid" CLASS="formSelect" onChange="document.selectGroup.submit();">
<?php
// -- GENERATE GROUP SELECTION LIST --
// Only admins can view hidden entries.
if ($_SESSION['usertype'] == "admin") {
$groupsql = "SELECT groupid, groupname FROM " . TABLE_GROUPLIST . " AS grouplist WHERE groupid >= 0 ORDER BY groupname";
}
else {
$groupsql = "SELECT groupid, groupname FROM " . TABLE_GROUPLIST . " AS grouplist WHERE groupid >= 0 AND groupid != 2 ORDER BY groupname";
}
$r_grouplist = mysql_query($groupsql, $db_link);
while ($tbl_grouplist = mysql_fetch_array($r_grouplist)) {
$selectGroupID = $tbl_grouplist['groupid'];
$selectGroupName = $tbl_grouplist['groupname'];
echo(" <OPTION VALUE=$selectGroupID");
if ($selectGroupID == $list->group_id) {
echo(" SELECTED");
}
echo(">$selectGroupName</OPTION>\n");
}
?>
</SELECT>
</FORM>
</TD>
<?php
// END MAILING LIST
}
?>
</TR>
</TABLE>
</TD>
</TR>
<TR>
<TD CLASS="infoBox">
<BR>
<CENTER>
<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=10 WIDTH=560>
<FORM NAME="mail_form" METHOD="post" ACTION="<?php echo(FILE_MAILSEND); ?>">
<?php
//** MAILING LIST **
if (empty($mail_to)) {
// INITIATE CHECKBOX NUMBER
// here's the test.
// take out checkbox numbers and assign them to array. the checked ones will automatically be submitted?
// $cb_id = 1;
// DISPLAY GROUP NAME
echo(" <TR VALIGN=\"top\">\n");
echo(" <TD WIDTH=560 COLSPAN=4 CLASS=\"listHeader\">$list->group_name</TD>\n");
echo(" </TR>\n");
// DISPLAY IF NO ENTRIES UNDER GROUP
if (mysql_num_rows($r_contact)<1) {
echo(" <TR VALIGN=\"top\">\n");
echo(" <TD WIDTH=560 COLSPAN=4 CLASS=\"listEntry\">No entries.</TD>\n");
echo(" </TR>\n");
}
// DISPLAY ENTRIES
while ($tbl_contact = mysql_fetch_array($r_contact)) {
$contact_fullname = $tbl_contact['fullname'];
$contact_lastname = $tbl_contact['lastname'];
$contact_firstname = $tbl_contact['firstname'];
$contact_id = $tbl_contact['id'];
echo("<TR VALIGN=\"top\">\n");
// DISPLAY NAME -- links are shown either as regular link or popup window
if ($options['displayAsPopup'] == 1) {
$popupLink = " onClick=\"window.open('" . FILE_ADDRESS . "?id=$contact_id','addressWindow','width=600,height=450,scrollbars,resizable,location,menubar,status'); return false;\"";
}
if (!$contact_firstname) {
echo("<TD WIDTH=150 CLASS=\"listEntry\"><B><A HREF=\"" . FILE_ADDRESS . "?id=$contact_id\"$popupLink>$contact_lastname</A></B></TD>\n");
}
else {
echo("<TD WIDTH=150 CLASS=\"listEntry\"><B><A HREF=\"" . FILE_ADDRESS . "?id=$contact_id\"$popupLink>$contact_fullname</A></B></TD>\n");
}
// DISPLAY E-MAILS
echo("<TD WIDTH=410 CLASS=\"listEntry\">");
$r_email = mysql_query("SELECT id, email, type FROM " . TABLE_EMAIL . " AS email WHERE id=$contact_id", $db_link);
$tbl_email = mysql_fetch_array($r_email);
$email_address = stripslashes( $tbl_email['email'] );
$email_type = stripslashes( $tbl_email['type'] );
if ( (eregi("old", $email_type)) || (empty($email_address)) ) {
$checkme = "";
} else {
$checkme = " CHECKED";
}
echo("<INPUT TYPE=\"checkbox\" NAME=\"mail_to[]\" VALUE=\"$email_address\"$checkme>");
$cb_id++;
if ($options['useMailScript'] == 1) {
echo("<A HREF=\"" .FILE_MAILTO. "?to=$email_address\">$email_address</A>");
}
else {
echo("<A HREF=\"mailto:$email_address\">$email_address</A>");
}
if ($email_type) {
echo(" ($email_type)");
}
while ($tbl_email = mysql_fetch_array($r_email)) {
$email_address = stripslashes( $tbl_email['email'] );
$email_type = stripslashes( $tbl_email['type'] );
echo("<BR><INPUT TYPE=\"checkbox\" NAME=\"mail_to[]\" VALUE=\"$email_address\">");
$cb_id++;
if ($options['useMailScript'] == 1) {
echo("<A HREF=\"" .FILE_MAILTO. "?to=$email_address\">$email_address</A>");
}
else {
echo("<A HREF=\"mailto:$email_address\">$email_address</A>");
}
if ($email_type) {
echo(" ($email_type)");
}
}
echo(" </TD>\n");
echo(" </TR>\n");
// END WHILE
}
?>
<SCRIPT LANGUAGE="JavaScript">
<!--
function restart() {
for (var i=0;i<=1000;++i) {
document.mail_form.elements[i].checked=false
}
}
// -->
</SCRIPT>
<TR>
<TD width="150" class="data"></TD>
<TD WIDTH=410 CLASS="data">
<A HREF="#" onClick="restart();return false;"><?php echo $lang['GROUP_NONE']?></A>
<BR><BR><BR>
</TD>
</TR>
<?php
// END MAILING LIST LIST GENERATION
} else {
// THIS IS FOR SINGLE E-MAILS
?>
<TR>
<TD width="200" class="data"><H4>To Email:</H4></TD>
<TD width="300" class="data">
<INPUT TYPE="text" CLASS="formMailbox" VALUE="<?php echo($mail_to);?>" NAME="mail_to" ><BR><BR>
</TD>
</TR>
<?php
}
// END, AND BEGIN COMMON STUFF
?>
<TR>
<TD WIDTH=200 CLASS="data"><H4>CC:</H4></TD>
<TD WIDTH=300 CLASS="data">
<INPUT TYPE="text" CLASS="formMailbox" VALUE="" NAME="mail_cc" SIZE=80><BR><BR>
</TD>
</TR>
<TR>
<TD WIDTH=200 CLASS="data"><H4>BCC:</H4></TD>
<TD WIDTH=300 CLASS="data">
<INPUT TYPE="text" CLASS="formMailbox" VALUE="" NAME="mail_bcc" SIZE=80><BR><BR>
</TD>
</TR>
<TR><TD WIDTH=200 CLASS="data"><H4>From:</H4></TD>
<TD WIDTH=300 CLASS="data"><?php echo $_SESSION['username']; ?>
<INPUT TYPE="hidden" VALUE="<?php echo $_SESSION['username'] ; ?>" NAME="mail_from_name" ><BR><BR>
</TD></TR>
<TR><TD WIDTH=200 CLASS="data"><H4>From Email:</H4></TD>
<TD width="300" class="data"><?php echo$mail_from; ?></TD></TR>
<TR><TD WIDTH=200 CLASS="data"><H4><?php echo $lang['MAIL_SUBJ']?>:</H4></TD>
<TD WIDTH=300 CLASS="data">
<INPUT TYPE="text" CLASS="formTextbox" VALUE="" NAME="mail_subject" SIZE=80><BR><BR>
</TD></TR>
<TR><TD WIDTH=200 CLASS="data"><H4><?php echo $lang['MAIL_MSG']?>:</H4></TD>
<TD WIDTH=300 CLASS="data">
<TEXTAREA CLASS="formTextarea" ROWS="20" COLS="75" NAME="mail_body"></TEXTAREA><BR><BR>
</TD></TR>
<TR><TD WIDTH=200 CLASS="data"></TD>
<TD WIDTH=300 CLASS="data">
<?php
// If there is valid email in FROM, then send mail from to mailsend with other values and dispaly the send mail button. Value set above when contact info obtained
if($SendMailButton == "Yes"){
echo " <INPUT TYPE=\"submit\" VALUE=\"".$lang['BTN_SEND']."\" NAME=\"sendEmail\" CLASS=\"formButton\"><BR>";
echo" <INPUT TYPE=\"hidden\" VALUE=\"$mail_from\" NAME=\"mail_from\" ><BR><BR>";
} ?>
</TD></TR>
</FORM>
</TABLE>
</CENTER>
<BR>
</TD>
</TR>
<?php
printFooter();
?>
</TABLE>
</CENTER>
</BODY>
</HTML>