Rev 5957 | Blame | Compare with Previous | Last modification | View Log | RSS feed
<%@LANGUAGE="VBSCRIPT"%><%'=====================================================' project_log_json.asp'' AJAX SUpport for project_log.asp'=====================================================%><%Option explicitResponse.ContentType = "text/html"Response.AddHeader "Content-Type", "text/html;charset=UTF-8"Response.CodePage = 65001Response.CharSet = "UTF-8"%><!--#include file="common/conf.asp"--><!--#include file="common/globals.asp"--><!--#include file="common/qstr.asp"--><!--#include file="common/common_subs.asp"--><SCRIPT LANGUAGE="VBScript" RUNAT=SERVER SRC="class/classaspJSON.vbs"></SCRIPT><%'------------ Variable Definition -------------Dim result : result = -1Dim SqlQryDim rsQry' Init the output JSON class' Operations can add data' Default data will be added at the endDim oJSON :Set oJSON = New aspJSONDim newitem'' Determine the size of the record setDim MaxCount : MaxCount = 0SqlQry = "select count(*) as count from PROJECT_ACTION_LOG"On Error Resume NextobjEH.ErrorRedirect = FALSEobjEH.TryORA ( OraSession )Set rsQry = OraDatabase.DbCreateDynaset( SqlQry, ORADYN_DEFAULT )objEH.CatchORA ( OraSession )If ((NOT rsQry.BOF) AND (NOT rsQry.EOF)) ThenMaxCount = rsQry("COUNT")End IfrsQry.CloseSet rsQry = Nothing' Basic HeaderoJSON.data("draw") = CInt(Request.QueryString("draw"))oJSON.data("recordsTotal") = MaxCountoJSON.data("recordsFiltered") = MaxCount' Assist in debugoJSON.data("start") = CInt(Request.QueryString("start"))oJSON.data("length") = CInt(Request.QueryString("length"))Dim vNamefor each vName in Request.QueryStringoJSON.data("sReq_" & vName) = Request.QueryString(vName)next' Extract selected rangeresult = 0dim firstRow,lastRowfirstRow = CInt(Request.QueryString("start"))lastRow = firstRow + CInt(Request.QueryString("length"))' Define the data items to extract from the database' Format is:' 1) Name of Database column' 2) Expression::Name of Database column' Name will be used for sorting puposes' Expression will be used for data retrieval'Dim dataCols: dataCols = Array ( _"TO_CHAR(PL.ACTION_DATETIME, 'Dy DD-Mon-YYYY HH:MI:SS')::PL.ACTION_DATETIME", _"PL.DESCRIPTION", _"PROJ_ID", _"RTAG_ID", _"AT.DESCRIPTION", _"FULL_NAME")' Split dataCols into two parts based on ::' FirstPart - Complex Expression' SecondPart - Simple Name for Result' If no '::' then Expression to be the simple bitDim x, posReDim dataExt(Ubound(dataCols))For x = Lbound(dataCols) to Ubound(dataCols)pos = InStr( dataCols(x), "::" )If pos > 0 ThendataExt(x) = Mid( dataCols(x), 1, pos - 1 )dataCols(x) = Mid(dataCols(x), pos + 2)ElsedataExt(x) = dataCols(x)End IfNext' Dim determine sorting optionsDim sortStringIf Request.QueryString("order[0][column]") <> "" ThensortString = " ORDER BY " & dataCols(CInt(Request.QueryString("order[0][column]")))sortString = sortString & " " & Request.QueryString("order[0][dir]")End If' Create a list of cols that we need. Avoids ambiguity in selectionsDim colList,colListJoinFor x = Lbound(dataCols) to Ubound(dataCols)colList = colList & colListJoin & dataExt(x)Dim asNameasName = Replace(dataCols(x) , "." , "_")if dataCols(x) <> asName Then colList = colList & " as " & asNamecolListJoin = ","NextDim BasicSqlBasicSql = "select " & colList &_" from PROJECT_ACTION_LOG pl,USERS u, ACTION_TYPE at" &_" where pl.USER_ID = u.USER_ID and pl.acttype_id = at.acttype_id" &_sortStringSqlQry = "select * from ( "&_"select a.*, ROWNUM rnum from (" & BasicSql &_") a where ROWNUM <= " & lastRow &_") where rnum >= " & firstRow' Assist in debugoJSON.data("BasicSql") = BasicSql'oJSON.data("SqlQry") = SqlQry' Perform the database querySet oJSON.data("data") = oJSON.Collection()On Error Resume NextobjEH.ErrorRedirect = FALSEobjEH.TryORA ( OraSession )Set rsQry = OraDatabase.DbCreateDynaset( SqlQry, ORADYN_DEFAULT )objEH.CatchORA ( OraSession )' Return all fields to the user as an arrayIf objEH.Finally ThenWhile (NOT rsQry.BOF) AND (NOT rsQry.EOF)Set newitem = oJSON.AddToCollection(oJSON.data("data"))Dim iifor ii = 0 to rsQry.Fields.Count - 1newitem(ii) = rsQry.Fields(ii)NextrsQry.MoveNextWendEnd IFrsQry.CloseSet rsQry = Nothing'' SQL error detection and reportingIf objEH.LastOraFailed ThenoJSON.data("error") = 1oJSON.data("emsgSummary") = objEH.MessageSummaryoJSON.data("emsgDetails") = objEH.MessageDetailsoJSON.data("SqlQry") = SqlQryEnd If'Return the objectResponse.Write oJSON.JSONoutput()Set oJSON = NothingCall Destroy_All_Objects%>