-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubscribers.cfm
258 lines (206 loc) · 9.02 KB
/
subscribers.cfm
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
<!---
Creating Co. : Hostek.com
Programmed by: Kaleb L.
Creation Date: 11/15/2014
--->
<!--- Timout setting for the contact importer --->
<cfsetting
requestTimeOut = "60000">
<!--- Included header --->
<cfinclude template="header.cfm">
<div id="dialog-confirm"></div>
<cfoutput>
<script type="text/javascript">
function conf(){
var r = confirm("Are you sure you wish to purge ALL contacts?");
if (r == true) {
window.location.href = "manage.cfm?key=#Application.key#§ion=subscribers&action=purge&transacted=#listlast(cgi.script_name,'/\')#";
} else {
x = "You pressed Cancel!";
}
}
</script>
</cfoutput>
<!--- Main content wrapper --->
<div class="wrapper">
<div class="subscribers">
<!--- Single address add form --->
<form action="" method="post" class="form-inline">
<strong>Add Email Address</strong><br />
<input type="text" name="EmailAddress" size="35" class="form-control" />
<input type="submit" name="Add" value="Add" class="btn btn-default" />
</form>
<!--- Check to see if the a request to import contacts has been initiated --->
<cfif StructKeyExists(Form, "FileContents") >
<!--- Ensure that the user has chosen a file to import --->
<cfif len(Form.FileContents) >
<!--- Create a temp name for the uploaded file --->
<cfset tempname = "#DateFormat(Now())##Hour(Now())##Minute(Now())##Second(Now())#">
<!--- Main function to import the CSV file --->
<cffile
action = "upload"
destination = "tmp\#tempname#.csv"
fileField="FileContents"
accept = "application/octet-stream"
mode = "644"
nameConflict = "MakeUnique">
<cffile action="read" file="tmp\#tempname#.csv" variable="csvfile">
<!--- Initiate the counter for how many email addresses were added --->
<cfset counter = 0 />
<cfloop index="index" list="#csvfile#" delimiters="#chr(10)##chr(13)#">
<!--- Check each entry to make sure it is a valid email address --->
<cfif #find("@", listgetAt('#index#',1, ','))# >
<!--- Increase the counter for each entry that passes --->
<cfset counter = counter + 1 />
<cfquery datasource="#Application.DSN#" name="MailerSubscribers" timeout="60000">
INSERT INTO `mailersubscribers`(`Email`) VALUES ('#REReplace(listgetAt(index,1, ','),"""","","ALL")#')
</cfquery>
</cfif>
</cfloop>
<!--- Success Pop-up --->
<cfoutput >
<div class="alert alert-success" role="alert">#counter# records added to the contacts database!</div>
</cfoutput>
<!--- Task to clean up the file in the tmp direcory --->
<cffile
action = "delete"
file = "tmp\#tempname#.csv">
<!--- If the form tries to submit an import without choosing a file. Display error --->
<cfelse>
<div class="alert alert-danger" role="alert">Please choose a file to import!</div>
</cfif>
<!--- CSV import form --->
<strong>Import/Export CSV Contact File</strong><br />
<form id="importcsv" class="form-inline" method="post" action="<cfoutput>#cgi.script_name#</cfoutput>"
name="uploadForm" enctype="multipart/form-data" style="display: inline-block;">
<input name="FileContents" class="form-control btn btn-default" type="file" accept="text/csv">
<input name="submit" type="submit" class="btn btn-success" data-toggle="modal" data-target="#myModal" value="Import Contacts">
</form>
<!--- Export contacts to CSV form --->
<form id="exportcsv"class="form" method="post" action="<cfoutput>#cgi.script_name#</cfoutput>"
name="exportForm" enctype="multipart/form-data" style="display: inline-block;">
<input type="hidden" name="Export" value="Export" />
<input name="submit" type="submit" class="btn btn-info" value="Export Contacts">
</form>
<!--- Processing window pop-up --->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" data-backdrop="static" data-keyboard="false">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
Please Wait...
<div class="progress">
<div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100" style="width: 100%">
</div>
</div>
</div>
</div>
</div>
</div>
<cfelse>
<!--- If FALSE, just show the Form. --->
<strong>Import/Export CSV Contact File</strong><br />
<form id="importcsv" class="form-inline" method="post" action="<cfoutput>#cgi.script_name#</cfoutput>"
name="uploadForm" enctype="multipart/form-data" style="display: inline-block;">
<input name="FileContents" class="form-control btn btn-default" type="file" accept="text/csv">
<input name="submit" type="submit" class="btn btn-success" data-toggle="modal" data-target="#myModal" value="Import Contacts">
</form>
<!--- Export contacts to CSV form --->
<form id="exportcsv"class="form" method="post" action="<cfoutput>#cgi.script_name#</cfoutput>"
name="exportForm" enctype="multipart/form-data" style="display: inline-block;">
<input type="hidden" name="Export" value="Export" />
<input name="submit" type="submit" class="btn btn-info" value="Export Contacts">
</form>
<!--- Processing window pop-up --->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" data-backdrop="static" data-keyboard="false">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
Please Wait...
<div class="progress">
<div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100" style="width: 100%">
</div>
</div>
</div>
</div>
</div>
</div>
</cfif>
<!--- Single address add lisenter --->
<cfif #StructKeyExists(form, "EmailAddress")#>
<cfquery datasource="#Application.DSN#" name="MailerSubscribers" timeout="60000">
INSERT INTO `mailersubscribers`(`Email`) VALUES ('#Form.EmailAddress#')
</cfquery>
</cfif>
<cfif #StructKeyExists(url, "pg")#>
<!--- Display all the contacts avalible in the database --->
<cfoutput>
<cfif #URL.pg# eq "all">
<cfquery datasource="#Application.DSN#" name="MailerSubscribers" timeout="60000">
SELECT * FROM mailersubscribers ORDER BY EMAIL
</cfquery>
<cfelseif #URL.pg# eq "0">
<cfquery datasource="#Application.DSN#" name="MailerSubscribers" timeout="60000">
SELECT * FROM mailersubscribers WHERE Email REGEXP "^[0-9]" ORDER BY EMAIL
</cfquery>
<cfelse>
<cfquery datasource="#Application.DSN#" name="MailerSubscribers" timeout="60000">
SELECT * FROM mailersubscribers WHERE Email LIKE "#URL.pg#%" ORDER BY EMAIL
</cfquery>
</cfif>
</cfoutput>
<cfelse>
<!--- Display all the contacts avalible in the database --->
<cfquery datasource="#Application.DSN#" name="MailerSubscribers" timeout="60000">
SELECT * FROM mailersubscribers
</cfquery>
</cfif>
<!--- Increase the count for each contact added --->
<cfquery datasource="#Application.DSN#" name="MailerStats" timeout="60000">
UPDATE `mailerstats` SET `ContactNumber`=#MailerSubscribers.RecordCount#
</cfquery>
<h2>Current Subscribers</h2>
<cfset byName = "0,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,all" />
<cfloop list="#byName#" index="i">
<cfoutput> <a href="#cgi.script_name#?pg=#i#" class="badge" >#i#</a></cfoutput>
</cfloop>
<table border="0" cellpadding="5px" class="table table-bordered table-striped">
<thead>
<tr>
<th>Email Address</th>
<th class="center">
<cfoutput>
<button type="button" id="btnOpenDialog" class="btn btn-danger btn-xs" title="Purge All Contacts" onclick="conf()">Purge</button>
</cfoutput>
</th>
</tr>
</thead>
<cfoutput query="MailerSubscribers">
<tr>
<td>#Email#</td>
<td class="center"><a href="manage.cfm?key=#Application.key#§ion=subscribers&action=remove&ID=#ID#&transacted=#listlast(cgi.script_name,'/\')#"><span class="glyphicon glyphicon-trash" style="color: red; font-size: 20;" title="Delete"></span></a></td>
</tr>
</cfoutput>
</table>
</div>
</div>
<cfif isDefined("Form.Export") >
<cfquery name="ContactExport" datasource="#Application.DSN#">
SELECT *
FROM mailersubscribers
ORDER BY Email
</cfquery>
<!--- Required for CSV export to function properly --->
<cfsetting enablecfoutputonly="yes">
<!--- Use a comma for a field delimitter, Excel will open CSV files --->
<cfset delim = 44>
<cfcontent type="text/csv">
<cfheader name="Content-Disposition" value="attachment; filename=SatyrMail-Contacts-#DateFormat(Now())##Hour(Now())##Minute(Now())##Second(Now())#.csv">
<!--- Output Column Headers --->
<cfoutput>Email #chr(delim)#</cfoutput>
<cfoutput>#chr(13)#</cfoutput> <!--- line break after column header --->
<!--- Spill out data from a query --->
<cfloop query="ContactExport">
<cfoutput>#ucase(email)# #chr(delim)#</cfoutput>
<cfoutput>#chr(13)#</cfoutput>
</cfloop>
</cfif>