forked from ArctosDB/arctos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MediaSearchDownload.cfm
277 lines (254 loc) · 8.85 KB
/
MediaSearchDownload.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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
<cfinclude template="/includes/_header.cfm">
<cfset title="Download Agreement">
<!--- make sure they have an account --->
<cfif not isdefined("cnt") OR len(#cnt#) is 0>
<cfset cnt=0>
</cfif>
<cfif not isdefined("session.username") OR len(#session.username#) is 0>
<span style="color: #FF0000">You must be a registered user to download data!</span> <br>
Click <a href="/login.cfm">here</a> to log in or create a user account.
<cfabort>
</cfif>
<cfif #action# is "nothing">
<cfquery name="getUserData" datasource="cf_dbuser">
SELECT
cf_users.user_id,
first_name,
middle_name,
last_name,
affiliation,
email
FROM
cf_user_data,
cf_users
WHERE
cf_users.user_id = cf_user_data.user_id (+) AND
username = '#session.username#'
</cfquery>
<cfoutput>
<table>
<form method="post" action="MediaSearchDownload.cfm" name="dlForm">
<input type="hidden" name="user_id" value="#getUserData.user_id#">
<input type="hidden" name="ssql" value="#ssql#">
<input type="hidden" name="action" value="continue">
<input type="hidden" name="cnt" value="#cnt#">
<tr>
<td colspan="2"><span style="font-weight: bold; font-style: italic;">
You must fill out this form before you may download data. Fields with a
<input type="text" size="2" class="reqdClr">
background color are required.
</span></td>
</tr>
<tr>
<td align="right" width="20%">First Name</td>
<td> <input type="text" name="first_name" value="#getUserData.first_name#" class="reqdClr"></td>
</tr>
<tr>
<td align="right">Middle Name</td>
<td><input type="text" name="middle_name" value="#getUserData.middle_name#"></td>
</tr>
<tr>
<td align="right">Last Name</td>
<td><input type="text" name="last_name" value="#getUserData.last_name#" class="reqdClr"></td>
</tr>
<tr>
<td align="right">Affiliation</td>
<td><input type="text" name="affiliation" value="#getUserData.affiliation#" class="reqdClr"></td>
</tr>
<tr>
<td align="right">Purpose of Download</td>
<cfquery name="ctPurpose" datasource="user_login" username="#session.dbuser#" password="#decrypt(session.epw,session.sessionKey)#">
select * from ctdownload_purpose
</cfquery>
<td>
<select name="download_purpose" size="1" class="reqdClr">
<cfloop query="ctPurpose">
<option value="#ctPurpose.download_purpose#">#ctPurpose.download_purpose#</option>
</cfloop>
</select>
</td>
</tr>
<tr>
<td align="right">Email</td>
<td><input type="text" name="email" value="#getUserData.email#"></td>
</tr>
<tr>
<td align="right">File Format</td>
<td>
<select name="fileFormat" size="1">
<option value="csv">CSV</option>
</select>
</td>
</tr>
<tr>
<td colspan="2">
These data are intended for use in education and research and may not be repackaged, redistributed, or sold in any form
without prior written consent from the Museum. Those wishing to include these data in analyses or reports must acknowledge
the provenance of the original data and notify the appropriate curator prior to publication. These are secondary data, and
their accuracy is not guaranteed. Citation of the data is no substitute for examination of specimens. The Museum and its staff
are not responsible for loss or damages due to use of these data.
</td>
</tr>
<tr>
<td colspan="2">
<input type="radio" name="agree" value="yes">
<a href="javascript: void(0);" onClick="dlForm.agree[0].checked='true'"><font color="##00FF00" size="+1">I agree that the data that I am now downloading are for my own use
and will not be repackaged, redistributed, or sold.</font></a>
</td>
</tr>
<tr>
<td colspan="2">
<input type="radio" name="agree" value="no" checked>
<a href="javascript: void(0);" onClick="dlForm.agree[1].checked='true'"><font color="##FF0000" size="+1">I
do not agree</font>.</a>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="Continue"
class="savBtn"
onmouseover="this.className='savBtn btnhov'"
onmouseout="this.className='savBtn'">
</td>
</tr>
</form>
</table>
</cfoutput>
</cfif>
<cfif #action# is "continue">
<!--- get the values they filled in --->
<cfif len(#first_name#) is 0 OR
len(#last_name#) is 0 OR
len(#download_purpose#) is 0 OR
len(#affiliation#) is 0>
You haven't filled in all required values! Please use your browser's back button to try again.
<cfabort>
</cfif>
<cfset thisDate = #dateformat(now(),"dd-mmm-yyyy")#>
<cfquery name="isUser" datasource="cf_dbuser">
select * from cf_user_data where user_id=#user_id#
</cfquery>
<!---- already have a user_data entry ---->
<cfif #isUser.recordcount# is 1>
<cfquery name="upUser" datasource="cf_dbuser">
UPDATE cf_user_data SET
first_name = '#first_name#',
last_name = '#last_name#',
affiliation = '#affiliation#'
<cfif len(#middle_name#) gt 0>
,middle_name = '#middle_name#'
</cfif>
<cfif len(#email#) gt 0>
,email = '#email#'
</cfif>
WHERE
user_id = #user_id#
</cfquery>
</cfif>
<cfif #isUser.recordcount# is not 1>
<cfquery name="newUser" datasource="cf_dbuser">
INSERT INTO cf_user_data (
user_id,
first_name,
last_name,
affiliation
<cfif len(#middle_name#) gt 0>
,middle_name
</cfif>
<cfif len(#email#) gt 0>
,email
</cfif>
)
VALUES (
#user_id#,
'#first_name#',
'#last_name#',
'#affiliation#'
<cfif len(#middle_name#) gt 0>
,'#middle_name#'
</cfif>
<cfif len(#email#) gt 0>
,'#email#'
</cfif>
)
</cfquery>
</cfif>
<!--- if they agree to the terms, send them to their download --->
<cfif agree is "yes">
<cfquery name="findIDs" datasource="user_login" username="#session.dbuser#" password="#decrypt(session.epw,session.sessionKey)#" cachedwithin="#createtimespan(0,0,60,0)#">
#preservesinglequotes(ssql)#
</cfquery>
<cfset header = "media_page,media_license,mime_type,media_type,preview_uri,media_uri,relationships,labels,number_tags,coordinates">
<cfset fileDir = Application.webDirectory>
<cfoutput>
<cfset variables.encoding="UTF-8">
<cfset fname = "ArctosMedia_#left(session.sessionKey,10)#.csv">
<cfset variables.fileName="#Application.webDirectory#/download/#fname#">
<cfscript>
variables.joFileWriter = createObject('Component', '/component.FileWriter').init(variables.fileName, variables.encoding, 32768);
variables.joFileWriter.writeLine(header);
</cfscript>
<cfloop query="findIDs">
<cfset oneLine='"http://arctos.database.museum/media/#media_id#"'>
<cfif license contains " href=">
<cfset bla=replace(license,'<a target="_blank" class="external" href="','')>
<cfset qpos=find('"',bla)>
<cfset bla=left(bla,qpos-1)>
<cfelse>
<cfset bla=license>
</cfif>
<cfset thisData=bla>
<cfset thisData=replace(thisData,'"','""','all')>
<cfset oneLine = '#oneLine#,"#thisData#"'>
<cfset thisData=mime_type>
<cfset thisData=replace(thisData,'"','""','all')>
<cfset oneLine = '#oneLine#,"#thisData#"'>
<cfset thisData=media_type>
<cfset thisData=replace(thisData,'"','""','all')>
<cfset oneLine = '#oneLine#,"#thisData#"'>
<cfset thisData=preview_uri>
<cfset thisData=replace(thisData,'"','""','all')>
<cfset oneLine = '#oneLine#,"#thisData#"'>
<cfset thisData=media_uri>
<cfset thisData=replace(thisData,'"','""','all')>
<cfset oneLine = '#oneLine#,"#thisData#"'>
<cfset thisData=relationships>
<cfset thisData=replace(thisData,'"','""','all')>
<cfset oneLine = '#oneLine#,"#thisData#"'>
<cfset thisData=labels>
<cfset thisData=replace(thisData,'"','""','all')>
<cfset oneLine = '#oneLine#,"#thisData#"'>
<cfset thisData=hastags>
<cfset thisData=replace(thisData,'"','""','all')>
<cfset oneLine = '#oneLine#,"#thisData#"'>
<cfset thisData=coordinates>
<cfset thisData=replace(thisData,'"','""','all')>
<cfset oneLine = '#oneLine#,"#thisData#"'>
<cfset oneLine = trim(oneLine)>
<cfscript>
variables.joFileWriter.writeLine(oneLine);
</cfscript>
</cfloop>
<cfscript>
variables.joFileWriter.close();
</cfscript>
<cflocation url="/download.cfm?file=#fname#" addtoken="false">
<a href="/download/#fname#">Click here if your file does not automatically download.</a>
</cfoutput>
</cfif>
<cfif #agree# is "no">
<cfoutput>
You must agree to the terms of usage to download these data.
<ul>
<li>Click <a href="/home.cfm">here</a> to return to the home page.</li>
<li>Use your browser's back button or click <a href="javascript: history.back();">here</a>
if you wish to agree to the terms and proceed with the download.</li>
<li>Email <a href="mailto: #Application.bugReportEmail#">#Application.bugReportEmail#</a> if you wish to discuss the terms of
usage.</li>
</ul>
<br>
<br>
</cfoutput>
</cfif>
</cfif>
<cfinclude template="/includes/_footer.cfm">