<% ' Zenkichi.com ' Common functions ' By Chris Prine 8/21/08 ' MySQL Database databaseFullDSN = "DRIVER={MySQL ODBC 3.51 Driver};SERVER=zenkichi.db.2396606.hostedresource.com" _ & ";UID=zenkichi" _ & ";PASSWORD=Adam0987" _ & ";DATABASE=zenkichi;option=3; port=3306" const zenAdminLogin="zenadmin" const zenAdminPass="7jail39" const zenAdminCookieName="ztoken" const zenPressPath="/images/press" zenPressPathAbs=server.MapPath(zenPressPath) ' -------------------------------------------------------------------------- ' Database comm functions function DBqueryArray(sqlStr, search) DBqueryArray=(DBqueryArrayFoundRows(sqlStr, search)>0) end function function DBqueryArrayFoundRows(sqlStr, search) ' General database query ' input ' sqlStr SQL string query ' output ' search results of query in array ' returns boolean for results DBqueryArrayFoundRows = 0 if debugArray then debugDump(sqlStr) else dim conntemp, rstemp set rstemp=Server.CreateObject("ADODB.recordset") 'set conntemp=server.createobject("adodb.connection") 'conntemp.open databaseFullDSN set rstemp=zenDBobj.execute(sqlStr) if NOT rstemp.eof then search = rstemp.getrows rstemp.close if InStr(sqlStr,"SQL_CALC_FOUND_ROWS") then set rstemp=zenDBobj.execute("SELECT FOUND_ROWS() AS A") DBqueryArrayFoundRows=MyCint(rstemp.fields.item("A")) rstemp.close else DBqueryArrayFoundRows = 1 end if else rstemp.close end if end if end function function DBQuerySingle(sqlStr) ' Returns single value ' Usually used for getting a single aggregate value dim rstemp, returnValue set rstemp=Server.CreateObject("ADODB.recordset") set rstemp=zenDBobj.execute(sqlStr) if NOT rstemp.eof then returnValue=rstemp.fields.item(0) else returnValue=null end if set rstemp=nothing DBQuerySingle=returnValue end function function DBqueryObject(sqlStr, search) ' General database query ' input ' sqlStr SQL string query ' output ' search results of query in recordset ' returns boolean for results dim conntemp 'set conntemp=server.createobject("ADODB.connection") set search=nothing set search=Server.CreateObject("ADODB.recordset") 'zenDBobj.open databaseFullDSN set search=zenDBobj.execute(sqlStr) if NOT search.eof then DBqueryObject = true else DBqueryObject = false end if 'conntemp.close end function sub DBOpen(dbObj) ' Call at top of page set dbObj=nothing set dbObj=server.createobject("ADODB.connection") dbObj.open databaseFullDSN end sub sub DBClose(dbObj) ' Call at end of page dbObj.close set dbObj=nothing end sub function DBcall(ais_sql) 'General database query 'aissql holds sql query 'mainly for inserts and updates where no info is returned if debugCall then debugDump(ais_sql) else dim rstemp set rstemp=zenDBobj.execute(ais_sql) set rstemp=zenDBobj.execute("SELECT LAST_INSERT_ID() AS lastid") DBcall = rstemp.fields.item("lastid") rstemp.close end if end function ' -------------------------------------------------------------------------- ' Database input untainting function DBsafe(str) ' returns a value that can safely used in a SQL statement DBsafe = replace(replace(str&"", "'", "''"),"\","\\") end function function DBstring(str) ' returns string that can be used as a value in a SQL statement if str & "" = "" then DBstring = "NULL" else DBstring = "'" & DBsafe(str) & "'" end function function DBnumber(str) ' returns string that can be converted to numerical value if Not IsNumeric(str & "") then DBnumber = "0" else DBnumber = DBsafe(replace(str, ",", "")) end if end function function DBdate(str) DBdate=DBstring(dateToMysql(str)) end function function dateToMysql(theDate) ' convert MS date format to MySQL Datetime (YYYY-MM-DD HH:MM:SS) dim outResult outResult = "" if isDate(theDate&"") then outResult = year(theDate) & "-" & LeadingZeros(month(theDate),2) & "-" & LeadingZeros(day(theDate),2) & " " _ & LeadingZeros(hour(theDate),2) & ":" & LeadingZeros(minute(theDate),2) & ":" & LeadingZeros(second(theDate),2) end if dateToMysql = outResult end function function LeadingZeros(theNumber, numLength) ' pad number with leading zeroes until the string length equals numLength dim outResult outResult = theNumber&"" do while len(outResult)"" then Set reObj = New RegExp reObj.Pattern = reg_pattern reObj.Global = True outString = reObj.Test(reg_string) Set reObj = nothing end if reg_match=outString end function function reg_replace(reg_pattern, reg_string, reg_replacement) dim outString,reObj outString="" if reg_string>"" then Set reObj = New RegExp reObj.Pattern = reg_pattern reObj.Global = True outString = reObj.Replace(reg_string,reg_replacement) Set reObj = nothing end if reg_replace=outString end function function textFieldReady(stringInput) dim theInp theInp=stringInput&"" if theInp>"" then theInp=replace(theInp, """", """) end if textFieldReady=theInp end function sub printHiddenInput(fname, fvalue) dim formatField formatField=fvalue&"" formatField = replace(formatField, """", """) response.Write("" & vbcrlf) end sub function returnAdminToken() dim tmpArr, returnString returnString="" if DBQueryArray("SELECT CAST(SHA(" & DBString(zenAdminLogin & zenAdminPass) & ") AS CHAR)", tmpArr) then returnString = Cstr(tmpArr(0,0)) end if returnAdminToken=returnString end function function textToHTML(textString) dim outString outString=textString&"" outString=replace(outString, vbcrlf, "
") outString=replace(outString, vbtab, " ") outString=replace(outString, " ", "  ") textToHTML=outString end function function pressImagePath(pressRecordNo) pressImagePath=zenPressPath & "/" & pressRecordNo & ".jpg" end function function pressImageThumbPath(pressRecordNo) pressImageThumbPath=zenPressPath & "/" & pressRecordNo & "thumb.jpg" end function function fieldToTextArea(inputText) dim copyText copyText=inputText&"" copyText=replace(copyText, "
", vbcrlf) copyText=replace(copyText, " ", vbtab) copyText=replace(copyText, " ", " ") copyText=replace(copyText, "<", "<") copyText=replace(copyText, ">", ">") fieldToTextArea=copyText end function %> <% menuPages="index.asp,reservation.asp,menu.asp,qanda.asp,press.asp" menuTitles="Home,Reservation,Menu,Q & A,Press" arrMenu=split(menuPages,",") arrTitles=split(menuTitles,",") currentPage = lcase(reg_replace("^/?(?:[^/]+/)+([^/]+)$", Request.ServerVariables("PATH_INFO"), "$1")) currentPage = lcase(reg_replace("^/?([^/]+)$", currentPage, "$1")) flashVars="" for m=0 to 4 targetURL=arrMenu(m) if targetURL=currentPage then flashVars="curtab=" & (m+1) next dim zenDBobj call DBOpen(zenDBobj) %> Zenkichi - Modern Japanese Brasserie - Brooklyn, NY
Zenkichi Modern Japanese Brasserie Phone 718-388-8985
77 N 6th St, Brooklyn, NY 11211, Map

Menu

<% if DBQueryArray("SELECT lMenuID,sMenu FROM tblMenu ORDER BY lMenuOrder,lMenuID", arrMenu) then response.write("") for m=0 to ubound(arrMenu,2) response.write("") if DBqueryArray("SELECT sMenuItem,sMenuItemPrice,sMenuItemDesc FROM tblMenuItem WHERE lMenuID=" & arrMenu(0,m) & " ORDER BY lMenuItemOrder,lMenuItemID", arrMItem) then for i=0 to ubound(arrMItem,2) response.write("") if arrMItem(2,i)>"" then response.write("") end if next end if next response.write("
" & arrMenu(1,m) & "
" & textToHTML(arrMItem(0,i)) & "" & arrMItem(1,i) & "
" & textToHTML(arrMItem(2,i)) & "
") end if %> <% call DBClose(zenDBobj) %>