forked from PAWECOGmbH/saaster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Application.cfc
298 lines (220 loc) · 10 KB
/
Application.cfc
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
component displayname="Application" output="false" extends="backend.myapp.ownApplication" {
// Datasource and custom variables
include template="config.cfm";
// Dynamic values
this.name = variables.applicationname;
this.sessiontimeout = variables.sessiontimeout;
this.pdf.type = variables.pdf_type;
setting requesttimeout = variables.requesttimeout;
// Fixed values
this.sessionmanagement = true;
this.setdomaincookies = true;
processingdirective pageEncoding="utf-8";
this.mappings["/"] = getDirectoryFromPath(getCurrentTemplatePath());
setTimezone("UTC+00:00"); // Do NOT change the standard timezone!!!
public boolean function onApplicationStart() {
application.datasource = variables.datasource;
// Dynamic values
application.projectName = variables.appName;
application.appOwner = variables.appOwner;
application.fromEmail = variables.fromEmail;
application.toEmail = variables.toEmail;
application.errorMail = variables.errorEmail;
if (variables.environment eq "dev") {
application.environment = "dev";
if (cgi.https eq "on") {
application.mainURL = "https://" & cgi.server_name;
} else {
application.mainURL = "http://" & cgi.server_name;
}
} else {
application.environment = "prod";
application.mainURL = variables.mainURL;
}
// Payrexx initialising
local.payrexxStruct = structNew();
local.payrexxStruct['payrexxAPIurl'] = variables.payrexxAPIurl;
local.payrexxStruct['payrexxAPIinstance'] = variables.payrexxAPIinstance;
local.payrexxStruct['payrexxAPIkey'] = variables.payrexxAPIkey;
application.payrexxStruct = local.payrexxStruct;
// Object initialising
application.objLog = new backend.core.com.log();
application.objGlobal = new backend.core.com.global();
application.objLanguage = new backend.core.com.language();
application.objSettings = new backend.core.com.settings();
application.objUser = new backend.core.com.user();
application.objCustomer = new backend.core.com.customer();
application.objLayout = new backend.core.com.layout();
application.objNotifications = new backend.core.com.notifications();
application.objSysadmin = new backend.core.com.sysadmin();
application.objMeta = new backend.core.com.meta();
// Save all choosable languages into a list
local.qLanguages = queryExecute(
options = {datasource = application.datasource},
sql = "
SELECT CONCAT(strLanguageISO, '|', strLanguage) as lang
FROM languages
WHERE blnChooseable = 1
ORDER BY intPrio
"
)
application.allLanguages = ValueList(local.qLanguages.lang);
// Load language struct and save it into the application scope
application.langStruct = application.objLanguage.initLanguages();
// Load system setting struct and save it into the application scope
application.systemSettingStruct = application.objSettings.initSystemSettings();
// Load layout setting struct and save it into the application scope
application.layoutStruct = application.objLayout.layoutSetting(application.systemSettingStruct.settingLayout);
ownApplicationStart();
return true;
}
public void function onSessionStart() {
// Check browser language
local.browserLng = application.objLanguage.getBrowserLng(cgi.http_accept_language).lng;
// Check whether the language is active in project
local.checkLng = findNoCase(local.browserLng, application.allLanguages);
// Save the language into the session
session.lng = local.checkLng ? local.browserLng : application.objLanguage.getDefaultLanguage().iso;
if (application.environment eq "dev") {
session.usersIP = variables.usersIP;
} else {
session.usersIP = cgi.remote_addr;
}
// Custom code
ownSessionStart();
return;
}
public boolean function onRequestStart(required string TargetPage) {
// Reinit Application
if (structKeyExists(url, "reinit") and url.reinit eq 1) {
structClear(APPLICATION);
onApplicationStart();
application.langStruct = application.objLanguage.initLanguages();
}
// Reinit Session
if (structKeyExists(url, "reinit") and url.reinit eq 2) {
structClear(SESSION);
onSessionStart();
}
// Reinit languages
if (structKeyExists(url, "reinit") and url.reinit eq 3) {
structDelete(session, "langStruct");
application.langStruct = application.objLanguage.initLanguages();
}
// Reinit Session AND Application AND languages
if (structKeyExists(url, "reinit") and url.reinit eq 4) {
structClear(SESSION);
structClear(APPLICATION);
onApplicationStart();
onSessionStart();
application.langStruct = application.objLanguage.initLanguages();
}
// Set the locale of the browser
local.browserLocale = application.objLanguage.getBrowserLng(cgi.http_accept_language).code;
// Set customers locale using his browser
setLocale(application.objLanguage.toLocale(language=local.browserLocale));
// Custom code
ownRequestStart();
return true;
}
public boolean function onRequest(required string TargetPage) {
// Create SEF URL
thiscontent = application.objGlobal.getSEF(replace(cgi.path_info,'/','','one'));
// Change language
if (structKeyExists(url, "l")) {
qCheckLanguage = queryExecute(
options = {datasource = application.datasource},
params = {
thisLng: {type: "nvarchar", value: url.l}
},
sql = "
SELECT COUNT(*) as cnt
FROM languages
WHERE strLanguageISO = :thisLng
"
)
if (qCheckLanguage.cnt gt 0) {
session.lng = url.l;
application.langStruct = application.objLanguage.initLanguages();
if (structKeyExists(session, "customer_id")) {
application.objCustomer.setProductSessions(session.customer_id, session.lng);
}
}
}
// Global variables
getTrans = application.objLanguage.getTrans;
getAlert = application.objGlobal.getAlert;
getLayout = application.layoutStruct;
logWrite = application.objLog.logWrite;
getMeta = application.objMeta.getMeta;
// Is there a redirect coming in url?
if (structKeyExists(url, "redirect")) {
session.redirect = application.mainURL & "/" & url.redirect;
} else if (structKeyExists(url, "del_redirect")) {
structDelete(session, "redirect");
}
// Check whether the user has access to corresponding sections
if (structKeyExists(session, "customer_id")) {
// More global variables (with customer session)
getTime = new backend.core.com.time(session.customer_id);
getCustomerData = application.objCustomer.getCustomerData(session.customer_id);
local.no_access = false;
if (thiscontent.noaccess) {
local.no_access = true;
} else {
if (structKeyExists(session, "admin") and !session.admin) {
if (thiscontent.onlyAdmin) {
getAlert('msgNoAccess', 'danger');
local.no_access = true;
}
}
if (structKeyExists(session, "superadmin") and !session.superadmin) {
if (thiscontent.onlySuperAdmin) {
getAlert('msgNoAccess', 'danger');
local.no_access = true;
}
}
if (structKeyExists(session, "sysadmin") and !session.sysadmin) {
if (thiscontent.onlySysAdmin) {
getAlert('msgNoAccess', 'danger');
local.no_access = true;
}
}
}
if (local.no_access) {
location url="#application.mainURL#/dashboard" addtoken="false";
}
} else {
// Protect the 'backend' folder excluding the pdf print page
if (listFirst(thiscontent.thisPath, "/") eq "backend" and !structKeyExists(session, "user_id")) {
if (structKeyExists(url, "pdf")) {
location url="#application.mainURL#/backend/core/views/invoices/print.cfm?pdf=#url.pdf#" addtoken="false";
} else {
getAlert('alertSessionExpired', 'warning');
location url="#application.mainURL#/login" addtoken="false";
}
}
// If someone is trying to call a .cfm file directly
if (thiscontent.noaccess) {
location url="#application.mainURL#" addtoken="false";
}
}
// Custom code
ownRequest();
include template="\#ARGUMENTS.TargetPage#";
return true;
}
public void function onError(struct exception, string eventName) {
if (application.environment eq "dev") {
writeOutput(arguments.exception);
} else {
// Send email with error
mail to="#application.errorMail#" from="#application.fromEmail#" subject="ERROR - #application.projectName#" type="html" {
writeOutput("<h2>An error occured!</h2>");
writeOutput(arguments.exception);
}
location url="/error.cfm" addtoken="false";
}
}
setting enablecfoutputonly = false;
}