<% response.buffer = true IF request.servervariables("HTTPS") = "off" THEN response.end END IF %> <% bytecount = Request.TotalBytes bytes = Request.BinaryRead(bytecount) IF bytecount <> 0 THEN Set stream = Server.CreateObject("ADODB.Stream") stream.Type = 1 'adTypeBinary stream.Open() stream.Write(bytes) stream.Position = 0 stream.Type = 2 'adTypeText stream.Charset = "utf-8" s = stream.ReadText() stream.Close() Set stream = nothing 'Response.write(s) Set oJSON = New aspJSON 'Load JSON string oJSON.loadJSON(s) 'Get single value api_key = oJSON.data("api_key") school_id = oJSON.data("school_id") pupil_id = oJSON.data("pupil_id") Set oJSON = Nothing END IF StrError = "None" StrAction = "None" IF api_key<>"" THEN 'run login IF api_key<> "" THEN IF (api_key="ndh032k8scs5pIHXSihd9I392hxeihwd0") THEN 'valid request ELSE StrError="Authentcation failed" END IF ELSE StrError = "Authentication data is required" END IF 'school id IF school_id<>"" AND IsNumeric(school_id) THEN 'ok ELSE StrError = "Invalid school data" END IF 'pupil id IF pupil_id <> "" AND IsNumeric(pupil_id) THEN 'ok ELSE StrError = "Invalid pupil data" END IF IF StrError <> "None" THEN 'print the errors Set oJSON = New aspJSON With oJSON.data .Add "status", "1" 'Create value .Add "message", "Authentication error" 'Create value End With Response.Write oJSON.JSONoutput() ELSE 'fetch expected pupil data SET rsTL = dbCBK.Execute("SELECT `name` from cbk_pupils WHERE schoolID='"&school_id&"' AND pupilID='"&pupil_id&"' limit 1") IF rsTL.EOF THEN StrError = "No pupil found" END IF DO WHILE NOT rsTL.EOF str_pupil_name=rsTL("name") rsTL.MoveNext loop rsTL.Close SET rsTL = Nothing IF str_pupil_name<>"" THEN str_html="
✔ "&str_pupil_name&"
" str_html=str_html&"

" 'success print api response Set oJSON = New aspJSON With oJSON.data .Add "status", "0" 'Create value .Add "message", ""&str_html&"" 'Create value End With Response.Write oJSON.JSONoutput() ELSE ' print failure response Set oJSON = New aspJSON With oJSON.data .Add "status", "1" 'Create value .Add "message", "No pupil found" 'Create value End With Response.Write oJSON.JSONoutput() END IF END IF ELSE 'no credentials print failure response StrError="Missing Credentials" Set oJSON = New aspJSON With oJSON.data .Add "status", "1" 'Create value .Add "message", ""&StrError&"" 'Create value End With Response.Write oJSON.JSONoutput() END IF %>