Files
Facilitor/APPL/Shared/Shared.inc
Peter Feij 413498318a 0-versie
svn path=/Website/trunk/; revision=6
2009-10-05 06:44:06 +00:00

259 lines
7.7 KiB
PHP
Raw Blame History

<% /*
$Revision: 1 $
$Modtime: 3-09-09 13:43 $
File: shared.inc
Description: Generieke functies die door elke pagina gebruikt worden.
Parameters:
Context: Vanuit ELK asp bestand
Note: Dus gebruik met mate
*/ %>
<!-- #include file="../Shared/logger.inc" -->
<!-- #include file="../Shared/m_connections.inc" -->
<!-- #include file="../Shared/header.inc" -->
<!-- #include file="../Shared/user.inc" -->
<%
var user_key=Session("user_key");
if (typeof user_key == "undefined")
{
// TODO: Is dit *de* plek om te proberen de user_key uit een cookie te halen?
user_key = -1;
user = null;
}
else
user = new Perslid(user_key);
// Voor FO gezet in shared/SetCaller.asp
var gCaller = null;
if (typeof Session("caller") == "object")
{
gCaller = Session("caller");
}
// Check for parameter pName and return the value
// If not specified return defVal
// If defVal not specified pName a required parameter
function getQParam(pName, defVal)
{
var rq = Request.Querystring(pName);
if (rq.count > 0)
return rq(1);
else
{
if (typeof defVal != 'undefined')
return defVal;
else // Error message will get to client and/or IIS logfiles
eval("INTERNAL_ERROR_QPARAMETER_" + pName + "_IS_MISSING"); // A required parameter was not supplied
}
}
// Check for parameter pName and return the Integer value
// If not specified return defVal
// If defVal not specified pName is a required parameter
// If relaxed==true then return defVal on invalid number
function getQParamInt(pName, defVal, relaxed)
{
var strval = getQParam(pName, defVal);
if (strval == "") return defVal;
var val = parseInt(strval, 10);
if (isNaN(val))
{
if (relaxed)
return defVal;
else
// Error message will get to client and/or IIS logfiles
eval("INTERNAL_ERROR_QPARAMETER_" + pName + "_IS_NOT_INTEGER"); // A required parameter was not supplied
}
else
return val;
}
// Check for parameter pName and return the Date value
// If not specified return defVal
// If defVal not specified pName is a required parameter
// defVal can be a date object or null
function getQParamDate(pName, defVal)
{
var val = getQParamInt(pName, -1);
if (val>0)
return new Date(val);
if (defVal instanceof Date)
{
return defVal;
}
if (defVal == null)
{
return null
}
// Error message will get to client and/or IIS logfiles
eval("INTERNAL_ERROR_QPARAMETER_" + pName + "_IS_NOT_DATE"); // A required parameter was not supplied
}
// Check for parameter pName and return all values
// Levert een string(!) op, eventueel gescheiden door komma's op
function getQMultiParam(pName, defVal)
{
var rq = Request.Querystring(pName);
if (rq.count > 0)
return String(rq);
else
{
if (typeof defVal != 'undefined')
return defVal;
else // Error message will get to client and/or IIS logfiles
eval("INTERNAL_ERROR_QMULTIPARAM_" + pName + "_IS_MISSING"); // A required parameter was not supplied
}
}
// Check for parameter pName and return the value
// If not specified or empty return defVal
// If defVal not specified pName is required
function getFParam(pName, defVal)
{
var rf = Request.Form(pName);
if (rf.count > 0 && rf(1)!="")
return rf(1);
else
{
if (typeof defVal != 'undefined')
return defVal;
else // Error message will get to client and/or IIS logfiles
eval("INTERNAL_ERROR_FPARAMETER_" + pName + "_IS_MISSING"); // A required parameter was not supplied
}
}
// Check for parameter pName and return the Integer value
// If not specified return defVal
// If defVal not specified pName is a required parameter
function getFParamInt(pName, defVal, relaxed)
{
var strval = getFParam(pName, defVal);
if (strval == "") return defVal;
var val = parseInt(strval, 10);
if (isNaN(val))
{
if (relaxed)
return defVal;
else
// Error message will get to client and/or IIS logfiles
eval("INTERNAL_ERROR_FPARAMETER_" + pName + "_IS_NOT_INTEGER"); // A required parameter was not supplied
}
else
return val;
}
// Check for parameter pName and return the Date value
// If not specified return defVal
// If defVal not specified pName is a required parameter
// defVal can be a date object or null
function getFParamDate(pName, defVal)
{
var val = getFParamInt(pName, -1);
if (val>0)
return new Date(val);
if (defVal instanceof Date)
{
return defVal
}
if (defVal == null)
{
return null
}
// Error message will get to client and/or IIS logfiles
eval("INTERNAL_ERROR_FPARAMETER_" + pName + "_IS_NOT_DATE"); // A required parameter was not supplied
}
// Check for parameter pName and return all values
// Levert een string(!) op, eventueel gescheiden door komma's op
function getFMultiParam(pName, defVal)
{
var rf = Request.Form(pName);
if (rf.count > 0)
return String(rf);
else
{
if (typeof defVal != 'undefined')
return defVal;
else // Error message will get to client and/or IIS logfiles
eval("INTERNAL_ERROR_FULTIPARAM_" + pName + "_IS_MISSING"); // A required parameter was not supplied
}
}
// lijst is een array van parameter namen ["loc_key", "geb_key"]
// params is optioneel een hash { loc_key: 345, geb_key: 34 }
// (zonder params wordt QueryString genomen)
// resultaat: "&loc_key=345&geb_key=34"
function buildTransitParam(lijst, params)
{
var i;
var result="";
for (i=0; i<lijst.length; i++)
{
var itm = lijst[i];
if (params && params[itm])
result = result + "&" + itm + "=" + params[itm];
else if (getQParam(itm, "")!="")
result = result + "&" + itm + "=" + getQParam(itm);
}
return result;
}
function padout(number) { return (number < 10) ? "0" + number : number; }
// This function should only be used to format display,
// <20> never as part of a computation.
function toTimeString(jsDate, bWithSeconds)
{
if (jsDate===null)
return "";
if (typeof jsDate == "object" && jsDate.type == 135/*adDBTimeStamp, oRs("datum")*/)
jsDate = new Date(jsDate.value);
if (typeof jsDate == "date") // een oRs("datum").value
jsDate = new Date(jsDate);
if (!jsDate)
return "";
jsDate = new Date(jsDate.valueOf() + 1); // rounding errors
ret = padout(jsDate.getHours()) + ":" + padout(jsDate.getMinutes());
if (bWithSeconds) ret += ":" + padout(jsDate.getSeconds());
return ret;
}
function toDateString(jsDate)
{
if (jsDate===null)
return "";
if (typeof jsDate == "object" && jsDate.type == 135/*adDBTimeStamp, oRs("datum")*/)
jsDate = new Date(jsDate.value);
if (typeof jsDate == "date") // een oRs("datum").value
jsDate = new Date(jsDate);
if (!jsDate)
return "";
return padout(jsDate.getDate()) + "-" + padout(jsDate.getMonth() + 1) + "-" + padout(jsDate.getFullYear());
}
function toDateTimeString(jsDate, bWithSeconds)
{
if (jsDate===null)
return "";
if (typeof jsDate == "object" && jsDate.type == 135/*adDBTimeStamp, oRs("datum")*/)
jsDate = new Date(jsDate.value);
if (typeof jsDate == "date") // een oRs("datum").value
jsDate = new Date(jsDate);
return toDateString(jsDate) + " " + toTimeString(jsDate, bWithSeconds)
}
%>