175 lines
5.0 KiB
Plaintext
175 lines
5.0 KiB
Plaintext
<cfscript>
|
||
/* Все глобальные функции экспортированы в request scope */
|
||
function plain2htm(s) {
|
||
return replace(replace(s, chr(13),'',"ALL"),chr(10),'<br/>', "ALL");
|
||
}
|
||
request.plain2htm = plain2htm;
|
||
|
||
function htm2plain(s) {
|
||
return replaceNoCase(s, '<br/>', '#chr(13)##chr(10)#', "ALL");
|
||
}
|
||
request.htm2plain = htm2plain;
|
||
|
||
function cleanHtm(s) {
|
||
return replaceList(s, '<,>,"', '<,>,"');
|
||
}
|
||
request.cleanHtm = cleanHtm;
|
||
|
||
function clean4CDATA(s) {
|
||
LF = chr(10);
|
||
return replaceNoCase(replaceList(s, '[,]', '&91;,&93;'),"<br>",LF,"ALL");
|
||
}
|
||
request.clean4CDATA = clean4CDATA;
|
||
|
||
function numFmt(num, decimalPlaces = 0){
|
||
var sFormat = ",";
|
||
if (decimalPlaces GT 0) {sFormat = sFormat & "." & repeatString("0", decimalPlaces);}
|
||
return replace(NumberFormat(num, sFormat), ",", " ", "ALL");
|
||
}
|
||
request.numFmt = numFmt;
|
||
|
||
function nFmt(num, decimalPlaces = 2){
|
||
if (num EQ 0) return "";
|
||
return numFmt(num, decimalPlaces);
|
||
}
|
||
request.nFmt = nFmt;
|
||
|
||
function dateFmt(date, sFormat = 'DD.MM.YYYY'){
|
||
return dateFormat(date, sFormat);
|
||
}
|
||
request.dateFmt = dateFmt;
|
||
|
||
function dateTimeFmt(date, sDateFormat = 'DD.MM.YYYY', sTimeFormat='HH:MM'){
|
||
return dateFormat(date, sDateFormat) & ' ' & timeFormat(date, sTimeFormat);
|
||
}
|
||
request.dateTimeFmt = dateTimeFmt;
|
||
|
||
function timeFmt(date, sFormat = 'HH:MM'){
|
||
return timeFormat(date, sFormat);
|
||
}
|
||
request.timeFmt = timeFmt;
|
||
|
||
function usrAuthenticated() {
|
||
return request.usr_id GT 0 AND NOT (request.usr_id EQ request.ANONYMOUS_USR_ID);
|
||
}
|
||
request.usrAuthenticated = usrAuthenticated;
|
||
|
||
function filterOn(filter) {
|
||
return (isStruct(filter) AND NOT structIsEmpty(filter));
|
||
}
|
||
request.filterOn = filterOn;
|
||
|
||
function stripWhiteSpace(sNumber) {
|
||
return reReplace(sNumber, "[[:space:]]", "", "ALL");
|
||
}
|
||
request.stripWhiteSpace = stripWhiteSpace;
|
||
/*
|
||
// never used
|
||
function cleanNumber(sNumber) {
|
||
var s = reReplace(sNumber, "[[:space:]]", "", "ALL");
|
||
if ( find(",", s) ) { //watch argument order!!!
|
||
// assume Russian format with decimal comma and spaces for thousand separator
|
||
return replace(s, ",", ".");
|
||
} else {
|
||
// assume English format with decimal point and commas for thousand separator
|
||
return replace(s, ",", "", "ALL");
|
||
}
|
||
}
|
||
request.cleanNumber = cleanNumber;
|
||
*/
|
||
|
||
/*https://cflib.org/udf/queryColumnToArray*/
|
||
/**
|
||
* Takes a selected column of data from a query and converts it into an array.
|
||
*
|
||
* @param query The query to scan. (Required)
|
||
* @param column The name of the column to return data from. (Required)
|
||
* @return Returns an array.
|
||
* @author Peter J. Farrell (pjf@maestropublishing.com)
|
||
* @version 1, July 22, 2005
|
||
*/
|
||
function queryColumnToArray(qry, column) {
|
||
var arr = arrayNew(1);
|
||
var ii = "";
|
||
var loop_len = arguments.qry.recordcount;
|
||
for (ii=1; ii lte loop_len; ii=ii+1) {
|
||
arrayAppend(arr, arguments.qry[arguments.column][ii]);
|
||
}
|
||
return arr;
|
||
}
|
||
request.queryColumnToArray = queryColumnToArray;
|
||
|
||
/* ************************************* */
|
||
|
||
function loginPasswordPolicyCheck(usr_id, login, passwd, passwd2) {
|
||
msg = "";
|
||
// для старого логина длина не проверяется, все равно ничего не поделаешь
|
||
if (NOT(usr_id GT 0) AND len(login) LE 3) {
|
||
msg="Слишком короткий логин (минимальная длина логина 3 символа)";
|
||
} else {
|
||
if (passwd NEQ passwd2) {
|
||
msg="Пароль и подтверждение не совпадают";
|
||
} else {
|
||
if (len(passwd) LT "8") msg="Слишком короткий пароль (минимальная длина пароля 8 символов)";
|
||
}
|
||
}
|
||
return msg;
|
||
}
|
||
request.loginPasswordPolicyCheck = loginPasswordPolicyCheck;
|
||
|
||
function i18(label,label_en=label) {
|
||
//примитивная 2-язычная версия
|
||
if (request.language EQ 'en') {
|
||
return label_en;
|
||
} else {
|
||
return label;
|
||
};
|
||
}
|
||
request.i18 = i18;
|
||
|
||
function passwordHashCreate(password) {
|
||
return GenerateArgon2Hash('#ARGUMENTS.password#', 'argon2id', 1, 16000, 2);
|
||
}
|
||
request.passwordHashCreate = passwordHashCreate;
|
||
|
||
function passwordHashCheck(password, passwordHash) {
|
||
/*dirty hack for Lucee 6*/
|
||
try {
|
||
return evaluate("Argon2CheckHash('#ARGUMENTS.password#', ARGUMENTS.passwordHash, 'argon2id')");
|
||
} catch(e) {} // for lucee 5 compatibility
|
||
return evaluate("Argon2CheckHash('#ARGUMENTS.password#', ARGUMENTS.passwordHash)"); //lucee 6
|
||
}
|
||
request.passwordHashCheck = passwordHashCheck;
|
||
|
||
function skuCode(area_code="", abstract_service_code="") {
|
||
var s="#arguments[1]#.#arguments[2]#";
|
||
if (arrayLen(arguments) GE 3) {
|
||
if (len(arguments[3]) GT 0) {
|
||
s="#s#.#arguments[3]#";
|
||
} else {
|
||
s="#s#.0";
|
||
};
|
||
};
|
||
if (arrayLen(arguments) GE 4) {
|
||
if (len(arguments[4]) GT 0) {
|
||
s="#s#.#arguments[4]#"
|
||
}
|
||
};
|
||
if (arrayLen(arguments) GE 5) {
|
||
var pricingModelSuffix=arguments[5];
|
||
s="#s#-#pricingModelSuffix#";
|
||
}
|
||
return s;
|
||
}
|
||
request.skuCode = skuCode;
|
||
|
||
function roundSafe(a, precision) {
|
||
return (isNumeric(a) AND isNumeric(precision)) ? round(a,precision) : a;
|
||
}
|
||
request.roundSafe = roundSafe;
|
||
|
||
</cfscript>
|
||
|
||
|
||
|