' ====================================================================================== ' Run Basic Code Generator ' Using SQLite databse tables, this generates a very simple DB list and ' maintenance system. You can sort by clicking the heading, do wild card drill down searches ' on multiple fields, create CSV files, and security with user/pass. ' It can create drop down tables and radio buttons for maintenance. ' The output is placed in \public\ with the name of the table you requested + .bas ' ====================================================================================== ver$ = "2.0" bf$ = "" ' ---------------------------------- ' Load Database ' ---------------------------------- [doDbLoad] cr$ = chr$(13) dirOf$ = DefaultDir$ + "\*.*" ' ------------------------------------------- ' Shell out directory ' ------------------------------------------- [dirShell] cls [dirShell1] html "
" button #dbex, "Exit", [main1] html "
" loc$ = strRep$(dirOf$,"*.*","") x$ = shell$("dir ";dirOf$) i = 1 while word$(x$,i,cr$) <> "" a$ = word$(x$,i,cr$) if trim$(a$) = "" then goto [dirNxt] if left$(a$,1) = " " then goto [dirNxt] if left$(a$,1) = cr$ then goto [dirNxt] type$ = mid$(a$,26,3) size$ = mid$(a$,30,9) size$ = strRep$(size$,",","") size = val(size$) if type$ <> "DIR" and size = 0 then goto [dirNxt] name$ = mid$(a$,40) a$ = strRep$(a$,"<","[") a$ = strRep$(a$,">","]") html left$(a$,39) link #ddir,name$, [doDir] #ddir setkey(type$;"|";loc$;name$) html "
" goto [dirNxt1] [dirNxt] print a$ [dirNxt1] i = i + 1 wend wait [doDir] type$ = word$(EventKey$,1,"|") name$ = word$(EventKey$,2,"|") if type$ = "DIR" then dirOf$ = name$;"\*.*" goto [dirShell] end if [dbLoad] cls loadDb$ = name$ open loadDb$ for input as #1 ' see if the file is sqlite format a$ = "x" 'if lof(#1) > 12 then a$ = input$(#1,13) a$ = lower$(a$) 'end if close #1 if left$(a$,13) <> "sqlite format" then ' check file format print "This is not a SQLite file" html "
this is not a SQLite file
" goto [dirShell1] end if dbFile$ = loadDb$ sqliteconnect #sql,dbFile$ ' Connect to the DB" CSSClass ".hide", "{visibility: hidden; height:0px; border:none}" ' CSS to hide buttons ------- ' ----------------------------------- ' get table names in the DB ' ----------------------------------- sql$ = " SELECT name FROM sqlite_master WHERE type = 'table' ORDER BY name" #sql execute(sql$) rows = #sql ROWCOUNT() numddTbls = rows dim ddTbls$(rows) for i = 1 to rows #row = #sql #nextrow() ddTbls$(i) = #row name$() next i wordWrap$ = "style='white-space: pre-wrap;";_ "white-space: -moz-pre-wrap;";_ "white-space: -pre-wrap;";_ "white-space: -o-pre-wrap;";_ "word-wrap: break-word'" q$ = """" dim type$(28) dim typeVal$(28) type$(01) = "" : typeVal$(01) = "" type$(02) = "BIGINT" : typeVal$(02) = "I" type$(03) = "BLOB" : typeVal$(03) = "C" type$(04) = "BOOLEAN" : typeVal$(04) = "B" type$(05) = "CHAR" : typeVal$(05) = "C" type$(06) = "CLOB" : typeVal$(06) = "C" type$(07) = "DATE" : typeVal$(07) = "D" type$(08) = "DATETIME" : typeVal$(08) = "DT" type$(09) = "DECIMAL" : typeVal$(09) = "I" type$(10) = "DOUBLE" : typeVal$(10) = "I" type$(11) = "FLOAT" : typeVal$(11) = "I" type$(12) = "INT" : typeVal$(12) = "I" type$(13) = "INTEGER" : typeVal$(13) = "I" type$(14) = "LONGBLOB" : typeVal$(14) = "C" type$(15) = "LONGTEXT" : typeVal$(15) = "C" type$(16) = "MEDIUMBLOB" : typeVal$(16) = "C" type$(17) = "MEDIUMINT" : typeVal$(17) = "I" type$(18) = "MEDIUMTEXT" : typeVal$(18) = "I" type$(19) = "SMALLINT" : typeVal$(19) = "I" type$(20) = "TEXT" : typeVal$(20) = "T" type$(21) = "TIME" : typeVal$(21) = "TI" type$(22) = "TIMESTAMP" : typeVal$(22) = "C" type$(23) = "TINYBLOB" : typeVal$(23) = "C" type$(24) = "TINYINT" : typeVal$(24) = "I" type$(25) = "TINYTEXT" : typeVal$(25) = "C" type$(26) = "VARCHAR" : typeVal$(26) = "C" type$(27) = "VARCHAR" : typeVal$(27) = "C" type$(28) = "YEAR" : typeVal$(28) = "I" numSqlType = 23 dim sqlType$(numSqlType) numHtType = 23 dim htType$(numHtType) sqlType$(01) ="INT" : htType$(01) ="" sqlType$(02) ="INTEGER" : htType$(02) ="" sqlType$(03) ="TINYINT" : htType$(03) ="" sqlType$(04) ="SMALLINT" : htType$(04) ="" sqlType$(05) ="MEDIUMINT" : htType$(05) ="" sqlType$(06) ="BIGINT" : htType$(06) ="" sqlType$(07) ="INT2" : htType$(07) ="" sqlType$(08) ="INT8" : htType$(08) ="" sqlType$(09) ="CHAR()" : htType$(09) ="" sqlType$(10) ="VARCHAR()" : htType$(10) ="" sqlType$(11) ="NCHAR()" : htType$(11) ="" sqlType$(12) ="NVARCHAR()" : htType$(12) ="" sqlType$(13) ="TEXT" : htType$(13) ="" sqlType$(14) ="CLOB" : htType$(14) ="""" goto [nxtFld] end if if upper$(right$(fld$,3)) = "URL" or upper$(left$(fld$,3)) = "URL" then print #f, "html """"" goto [nxtFld] end if if upper$(right$(fld$,5)) = "EMAIL" or upper$(left$(fld$,5)) = "EMAIL" then print #f, "html """"" goto [nxtFld] end if print #f, "html """"" [nxtFld] if i mod 3 <> 0 then print #f, "html """"" else print #f, "html """"" end if next i print #f, "html """"" print #f, "if acd$ <> """" and acd$ <> ""View"" then" print #f, " button #acd, acd$, [";refTbl$;"doAcd]" print #f, " #acd setkey(this";refTbl$;"rowid$)" 'if imgField$ <>"" then ' print #f, "button #upload,""Upload"" ,[doUpload]" ' print #f, " #upload setid(""upload"")" ' print #f, " #upload setkey(this";refTbl$;"rowid$)" 'end if print #f, "end if" print #f, "html "" """ print #f, " button #ex, ""Exit"", [";refTbl$;"List]" print #f, " #ex cssclass(""extBtn"")" print #f, "html """"" print #f, "" if imgField$ <>"" then print #f, "if acd$ = ""Accept Upload"" then gosub [doUpload]" print #f, "" end if if imgField$ <>"" then print #f, "if ";imgField$;"$ <> """" then" print #f, " html ""
""" print #f, " img$ = imgDir$ + ";imgField$;"$" print #f, " files #f,img$" print #f, " if #f HASANSWER() <> 0 then" print #f, " #f nextfile$()" print #f, " ext$ = upper$(word$(";imgField$;"$,2,"".""))" print #f, " imgId$ = #f NAME$()" print #f, " medId$ = ";imgField$;"$" print #f, " mediaBig$ = ""Y""" print #f, " gosub [media] ' show media with controls" print #f, " end if" print #f, " html ""
""" print #f, "end if" end if print #f, "wait" print #f, "" print #f, "' =====================================" print #f, "' Do requested Add Change Delete" print #f, "' =====================================" print #f, "[";refTbl$;"doAcd]" print #f, "" print #f, "if acd$ = ""Delete"" then" if imgField$ <> "" then print #f, " if ";imgField$;"$ <> """" then" print #f, " img$ = imgDir$ + ";imgField$;"$" print #f, " files #f,img$" print #f, " if #f HASANSWER() <> 0 then kill img$ ' kill image on disk" print #f, "" print #f, " img$ = imgDir$ + ""TN_"" + ";imgField$;"$" print #f, " files #f,img$" print #f, " if #f HASANSWER() <> 0 then kill img$ ' kill thumbnail image on disk" print #f, " end if" end if print #f, " sql$ = ""DELETE FROM ";tbl$;" WHERE rowid = '"";this";refTbl$;"rowid$;""'""" print #f, " goto [";refTbl$;"execACD]" ' execute Add Change Delete print #f, "end if" print #f, "" if ctlField$ = "rowid" then colNames$ = colNames$ + "rowid," print #f, "dbFields$ = """;left$(colNames$,len(colNames$)-1);""" " print #f, "" print #f, "' ---------------------------------------------" print #f, "' Get data from the screen" print #f, "' ---------------------------------------------" for i = 1 to numFields fld$ = colName$(i) gosub [getTypeVal] for j = 1 to ddSel if fld$ = ddSelddField$(j) and ddSelddType(j) = 3 then ' Test for checkboxs print #f, "" print #f, "'-------------- ";fld$;" -- checkbox --------" print #f, fld$;"$ = """"" print #f, "sep$ = """"" print #f, "for i = 1 to sel";fld$;"Rows" print #f, " id$ = """;fld$;""" + str$(i)" print #f, " x$ = #request get$(id$)" print #f, " if x$ <> """" then" print #f, " ";fld$;"$ = ";fld$;"$ + sep$ + x$" print #f, " sep$ = "",""" print #f, " end if" print #f, "next i" goto [nxtInFld] end if next j if fld$ <> ctlField$ then print #f, fld$;"$ = #request get$(""";fld$;""") '- ";fld$;" -" gosub [getTypeVal] if thisTypeVal$ = "I" then print #f, fld$;" = val(";fld$;"$)" end if end if [nxtInFld] next i 'print #f, "if errNum > 0 then" 'print #f, " gosub [doMsg]" 'print #f, " wait" 'print #f, "end if" 'print #f, "" q$ = "" a$ = "" b$ = "" preC$ = ",'"";" aftC$ = ";""'" preI$ = ","";" aftI$ = ";""" for i = 1 to numFields fld$ = colName$(i) gosub [getTypeVal] print fld$;"--->";thisTypeVal$ if ctlField$ <> "rowid" and fld$ = "rowid" then goto [nxtSqFld] if thisTypeVal$ = "C" or thisTypeVal$ = "T" or thisTypeVal$ = "D" then print #f, fld$;"$ = dblQuote$(";fld$;"$)" a$ = a$ + preC$;fld$;"$";aftC$ else a$ = a$ + preI$ + "val(" + fld$ + "$)" + aftI$ end if [nxtSqFld] next i 'print "B4:";a$ if left$(a$,7) = ","";val(" then a$ = mid$(a$,4) if left$(a$,4) <> "val(" then a$ = """'"";" + a$ if right$(a$,2) = """'" then a$ = a$ + """" if right$(a$,2) = ";""" then a$ = left$(a$,len(a$) -2) 'print a$ 'input xxx ' ------- create SQL update command c$ = chr$(10) s$ = """UPDATE ";tbl$;" SET " for i = 1 to numFields fld$ = colName$(i) if fld$ = "rowid" then goto [nxtSq1Fld] gosub [getTypeVal] if thisTypeVal$ = "I" or thisTypeVal$ = "F" then s$ = s$ + c$ + fld$;" = "";";fld$;";""" else s$ = s$ + c$ + fld$;" = '"";";fld$;"$;""'" end if c$ = ",";chr$(10) [nxtSq1Fld] next i print #f, "" print #f, "if acd$ = ""Change"" then " print #f, "sql$ = ";s$;" WHERE ";ctlField$;" = '"";this";refTbl$;"rowid$;""'""" print #f, "goto [";refTbl$;"execACD]" print #f, "END IF" print #f, "" print #f, "if acd$ = ""Add"" or acd$ = ""AddLike"" then " print #f, " ";ctlField$;" = useNum(""";tbl$;""",""";ctlField$;""")" print #f, " ";ctlField$;"$ = str$(";ctlField$;")" print #f, "END IF" print #f, "dbVals$ = ";a$ print #f, "sql$ = ""INSERT or REPLACE into ";tbl$;" (""; dbFields$; "") VALUES (""; dbVals$; "")""" print #f, "" print #f, "[";refTbl$;"execACD]" print #f, "#sql execute(sql$)" 'print #f, "#sql disconnect()" print #f, "" print #f, "goto [";refTbl$;"List]" print #f, "" print #f, "' ----------------------------" print #f, "' They want Lines per page" print #f, "' ----------------------------" print #f, "[doLpp]" print #f, "if lpp = 0 then lpp = 20" print #f, "lpp = min(10,lpp)" print #f, "goto [";refTbl$;"List]" print #f, "" print #f, "' ----------------------------" print #f, "' They want next page" print #f, "' ----------------------------" print #f, "[doNext]" print #f, "lastPageNum = val(EventKey$)" print #f, "pageNum = val(#pageNum contents$())" print #f, "if lastPageNum = pageNum then pageNum = pageNum + 1" print #f, "goto [";refTbl$;"List]" print #f, "" print #f, "' ----------------------------" print #f, "' They want prev page" print #f, "' ----------------------------" print #f, "[doPrev]" print #f, "lastPageNum = val(EventKey$)" print #f, "pageNum = val(#pageNum contents$())" print #f, "if lastPageNum = pageNum then pageNum = pageNum - 1" print #f, "if pageNum < 1 then pageNum = 1" print #f, "goto [";refTbl$;"List]" print #f, "" print #f, "' -----------------------------------" print #f, "' They want to see Tile" print #f, "' -----------------------------------" print #f, "[seeTile]" print #f, "seeTile$ = EventKey$" print #f, "if seeTile$ = ""Y"" then" print #f, " seeTile$ = ""N""" print #f, " else" print #f, " seeTile$ = ""Y""" print #f, "end if" print #f, "goto [";refTbl$;"List]" print #f, "" print #f, "' -----------------------------------" print #f, "' They want to see or not see Photos" print #f, "' -----------------------------------" print #f, "[seePhoto]" print #f, "seePhoto$ = EventKey$" print #f, "if seePhoto$ = ""Y"" then" print #f, " seePhoto$ = ""N""" print #f, " else" print #f, " seePhoto$ = ""Y""" print #f, "end if" print #f, "goto [";refTbl$;"List]" print #f, "" print #f,"' ---------------------------------------------" print #f, "' User Search screen" print #f, "' Change srchFields$ for allowed search fields" print #f, "' ---------------------------------------------" print #f, "[";refTbl$;"doSearch]" print #f, " cls" print #f, "wa$ = """"" print #f, "html bf$;""" print #f, "
Search for ";tbl$;"""" print #f, "html ""
""" print #f, "html bf$;""""" print #f, "for i = 1 to ";refTbl$;"numSrch" print #f, " html """" " print #f, " if i mod 4 = 0 then html """"" print #f, "next i" print #f, "html ""
"";";refTbl$;"srchDescr$(i);""""" print #f, " sVar$ = ""#srch("";i;"")""" print #f, " textbox #sVar$,"""" " print #f, " html ""
""" print #f, "html bf$;""
""" print #f, " button #find, ""Search"", [";refTbl$;"doFind]" print #f, "" print #f, "html """"" print #f, " button #exit, ""Exit"", [";refTbl$;"List]" print #f, " #exit cssclass(""extBtn"")" print #f, "html ""
""" print #f, "" print #f, "html bf$;""
" print #f, " " print #f, " " print #f, " " print #f, " " print #f, " " print #f, " " print #f, " " print #f, " " print #f, " " print #f, " " print #f, " " print #f, " " print #f, " " print #f, "
Using wild card (*)
*beforeSearch for ends with
after*Search for begins with
*both*Contains the value somewhere
NoneMust match
Using operation Code
>Greater Than
<Less Than
<>Not Equal To
=Equal To
<=Less Than or Equal To
>=Greater Than or Equal To
Note: To find items with values use <> ''
""" print #f, "" print #f, "wait" print #f, "" print #f, "[";refTbl$;"doFind]" print #f, refTbl$;"dbWhere$ = """"" print #f, "for i = 1 to ";refTbl$;"numSrch" print #f, " oVar$ = ""#srch("";i;"")""" print #f, " srch$ = trim$(#oVar$ contents$())" print #f, "" print #f, " if srch$ <> """" then" print #f, " wld$ = goWild$(";refTbl$;"srchSel$(i),srch$)" print #f, " ";refTbl$;"dbWhere$ = ";refTbl$;"dbWhere$ + wld$" print #f, " end if" print #f, "next i" print #f, "if ";refTbl$;"dbWhere$ <> """" then ";refTbl$;"dbWhere$ = "" WHERE "" + ";refTbl$;"dbWhere$" print #f, "numRecords = 0" print #f, "goto [";refTbl$;"List]" print #f, "wait" print #f, "" print #f, " FUNCTION goWild$(fldDot$,str$)" print #f, " global wa$" print #f, " goWild$ = trim$(str$)" print #f, " l = len(goWild$)" print #f, " if l > 0 then" print #f, " if left$(goWild$,2) = ""<>"" then op$ = "" <> """ print #f, " if left$(goWild$,2) = ""!="" then op$ = "" <> """ print #f, " if left$(goWild$,2) = ""<="" then op$ = "" <= """ print #f, " if left$(goWild$,2) = ""=<"" then op$ = "" <= """ print #f, " if left$(goWild$,2) = "">="" then op$ = "" >= """ print #f, " if left$(goWild$,2) = ""=>"" then op$ = "" >= """ print #f, "" print #f, " if op$ <> """" then" print #f, " goWild$ = trim$(mid$(goWild$,3))" print #f, " if goWild$ = ""''"" then goWild$ = """"" print #f, " goto [endIt]" print #f, " end if" print #f, " if left$(goWild$,1) = "">"" then op$ = "" > """ print #f, " if left$(goWild$,1) = ""<"" then op$ = "" < """ print #f, " if left$(goWild$,1) = ""="" then op$ = "" = """ print #f, "" print #f, " if op$ <> """" then" print #f, " goWild$ = trim$(mid$(goWild$,2))" print #f, " if goWild$ = ""''"" then goWild$ = """"" print #f, " goto [endIt]" print #f, " end if" print #f, " op$ = "" LIKE """ print #f, "" print #f, " if INSTR(goWild$,""*"") <> 0 then wld$ = ""Y""" print #f, " if INSTR(goWild$,""%"") <> 0 then wld$ = ""Y""" print #f, " if wld$ <> ""Y"" then goWild$ = goWild$ + ""%""" print #f, " if right$(goWild$,1) = ""*"" then goWild$ = left$(goWild$,l - 1) + ""%""" print #f, " if left$(goWild$,1) = ""*"" then goWild$ = ""%"" + mid$(goWild$,2)" print #f, "[endIt]" print #f, " goWild$ = wa$;fldDot$;op$;""'"";goWild$;""'""" print #f, " wa$ = "" AND """ print #f, " else" print #f, " goWild$ = """"" print #f, " end if" print #f, " END FUNCTION" print #f, "" print #f, "' -----------------------------------------" print #f, "' sort header" print #f, "' -----------------------------------------" print #f, "[sortHdr]" print #f, "sortNum = val(EventKey$)" print #f, "if sortNum = preSortNum then" print #f, " if ad$ = """" then ad$ = "" desc"" else ad$ = """"" print #f, "end if" print #f, "if sortNum <> preSortNum then ad$ = """"" print #f, refTbl$;"orderBy$ = "" ORDER BY "" + strRep$(hdrSort$(sortNum),""^^"",ad$)" print #f, refTbl$;"sortBy$ = hdrSort$(sortNum)" print #f, "preSortNum = sortNum" print #f, "goto [";refTbl$;"List]" print #f, "" print #f, "' ============================================" print #f, "' List Heading" print #f, "' ============================================" print #f, "[";refTbl$;"Heading]" print #f, "' ---------------------------------------" print #f, "' Did they change the lines per page lpp" print #f, "' ---------------------------------------" print #f, "x = #lpp ISNULL()" print #f, "if x = 0 then lpp = val(#lpp contents$())" print #f, "" print #f, "pageNum = max(1,pageNum) ' make sure it has a page number" print #f, "if lpp < 1 then lpp = 30 ' lines per page must be specified" print #f, "lpp = max(5,lpp) ' make sure it has a least 5 lines per page" print #f, "lpp = min(100,lpp) ' do not allow over 100 lines per page" print #f, "" print #f, "totPages = int(numRecords / lpp)" print #f, "if lpp * totPages <> numRecords then totPages = totPages + 1" print #f, "pageNum = min(totPages,pageNum)" print #f, "pageNum = max(1,pageNum)" print #f, "limitBeg = (pageNum * lpp) - lpp 'limit begin value" print #f, "" print #f, "dispLine = 0" print #f, "" print #f, "limit$ = "" LIMIT "" ; limitBeg ; "","" ; lpp" print #f, "" print #f, "html bf$;""""" print #f, "html """"" print #f, "" print #f, "if runPass$ <> ""Y"" then" print #f, "html """"" print #f, "end if" print #f, "" print #f, "if upper$(loginCanMaint$) = ""Y"" then" print #f, "html """"" print #f, "end if" print #f, "" print #f, "html """"" print #f, "" print #f, "html ""
""" print #f, " button #add, ""Login"",[doLogin]" print #f, " #add setkey(0)" print #f, "html """"" print #f, " button #add, ""Add"", [";refTbl$;"Add]" print #f, " #add setkey(0)" print #f, "html """"" print #f, " button #exp, ""CSV"", [exportCsv]" print #f, "html """"" print #f, " button #help, ""Help"",[";refTbl$;"doHelp]" print #f, " #help cssclass(""lBtn"")" print #f, "" print #f, "html """"" print #f, " button #exit, ""Exit"",[doExit]" print #f, " #exit setid(""exitMe"")" print #f, " #exit cssclass(""extBtn"")" print #f, "if runPass$ = ""Y"" then" print #f, " html """"" print #f, "end if" print #f, "html ""Records:"";numRecords" print #f, "html ""Pages:"";totPages" print #f, "html """"" print #f, "html """"" print #f, " button #prev, ""Prev"",[doPrev]" print #f, " #prev setkey(pageNum)" print #f, "html """"" print #f, "html """"" print #f, " TEXTBOX #pageNum, pageNum,2" print #f, "" print #f, "html """"" print #f, "html """"" print #f, " button #next, ""Next"",[doNext]" print #f, " #next setkey(pageNum)" print #f, "html """"" print #f, "html """"" print #f, " button #lpp, ""Lpp"",[doLpp]" print #f, "html """"" print #f, " TEXTBOX #lpp, lpp,2" print #f, "html """"" if imgField$ <>"" then print #f, "' -----------------------------------------" print #f, "' flip/flop media Tile and See buttons" print #f, "' -----------------------------------------" print #f, "html """"" print #f, "button #til, ""Tile"",[seeTile]" print #f, " #til setkey(seeTile$)" print #f, "html """"" print #f, "if seeTile$ = ""Y"" then" print #f, " html ""Yes""" print #f, " else" print #f, " html ""No""" print #f, "end if" print #f, "html """"" print #f, "html """"" print #f, "button #sep, ""See Photo"",[seePhoto]" print #f, " #sep setkey(seePhoto$)" print #f, "html """"" print #f, "if seePhoto$ = ""Y"" then" print #f, " html ""Yes""" print #f, " else" print #f, " html ""No""" print #f, "end if" end if print #f, "html ""
""" 'TEXTBOX #lpp, lpp,2 html "" print #f, "html bf$;""""" print #f, "html ""
Sort""" print #f, "html """";";refTbl$;"sortBy$" print #f, "html """"" print #f, " button #srch, ""Search"",[";refTbl$;"doSearch]" print #f, " #srch setkey(srchData$)" print #f, "html """";";refTbl$;"dbWhere$" print #f, "html ""
""" print #f, "[headingMsg]" print #f, "html """"" print #f, "html """"" print #f, "html """"" print #f, "html """"" print #f, "html ""
""" print #f, "gosub [doMsg]" print #f, "RETURN" print #f, "" if imgField$ <>"" then print #f, "' -----------------------------------------" print #f, "' Do Upload image, video, music" print #f, "' -----------------------------------------" print #f, "[doUpload]" print #f, "" print #f, "upload """"; uploadId$" print #f, "upFileName$ = word$(uploadId$,1,""."")" print #f, "upFileExt$ = word$(uploadId$,2,""."")" print #f, "toUpFileName$ = upFileName$" print #f, "" print #f, "f$ = upper$(left$(""";tbl$;""",3))" 'first 3 letters print #f, "f$ = f$ + right$(""0000""+";ctlField$;"$,4)" print #f, "f$ = f$ + ""."" + upFileExt$" print #f, "toUpFileName$ = f$" print #f, "photoId$ = toUpFileName$" print #f, "f$ = imgDir$;uploadId$" print #f, "upCount = 0" print #f, "tf$ = imgDir$;toUpFileName$" print #f, "files #f, tf$" print #f, "if #f HASANSWER() then kill tf$" print #f, "" print #f, "' -------------------------------------" print #f, "' load media to photo directory" print #f, "' -------------------------------------" print #f, "OPEN uploadId$ FOR binary AS #f" print #f, "filedata$ = input$(#f, LOF(#f))" print #f, "CLOSE #f" print #f, "" print #f, "OPEN tf$ FOR binary AS #f" print #f, "PRINT #f, filedata$" print #f, "CLOSE #f" print #f, "" print #f, "sql$ = ""UPDATE ";tbl$;" SET ";imgField$;" = '"";photoId$;""' WHERE ";ctlField$;" = "";";ctlField$;"$" print #f, "#sql execute(sql$)" print #f, "" if useMgk$ = "Y" then print #f, "' ----------------------------------------------" print #f, "' create thumbnail file with TN_ file prefix" print #f, "' ----------------------------------------------" print #f, "filename$ = ";imgField$;"$ 'photo name" print #f, "newWidth = 150 ' desired width if thumbnail" print #f, "newFilename$ = ""TN_"" + filename$ ' Create the new filename with ""tn_"" prepended" print #f, "" print #f, "' Full path to magick.exe with quotes around it" print #f, "magickPath$ = chr$(34) + mgkLoc$ + chr$(34)" print #f, "" print #f, "inputFile$ = chr$(34) + imgDir$ + filename$ + chr$(34) ' Quote the image file paths" print #f, "outputFile$ = chr$(34) + imgDir$ + newFilename$ + chr$(34)" print #f, "" print #f, "' Complete command string" print #f, "command$ = magickPath$ + "" convert "" + inputFile$ + "" -resize "" + str$(newWidth) + ""x "" + outputFile$" print #f, "x$ = shell$(command$) ' shell out image magic command" print #f, "" print #f, "' Optionally check if file was created" print #f, "'open imgDir$ + newFilename$ for binary as #f" print #f, "'print #f, ""Thumbnail created, size = ""; lof(#f); "" bytes""" print #f, "'close #f" end if print #f, "html """"" print #f, "html "";""" print #f, "html """"" print #f, "RETURN" end if print #f, "" print #f, "' -------------------------------------------" print #f, "' Export to CSV based on sort and search" print #f, "' -------------------------------------------" print #f, "[exportCsv]" print #f, "q1$ = chr$(34) + "","" + chr$(34)" print #f, "q2$ = chr$(34)" print #f, "html """"" print #f, "" print #f, "#sql execute(sql$)" print #f, "colNames$ = #sql columnnames$()" print #f, "colNames$ = strRep$(colNames$,"" "","""")" print #f, "csvHead$ = q2$ + strRep$(colNames$,"","",q1$) + q2$" print #f, "" print #f, "open DefaultDir$ + ""\public\";refTbl$;".csv"" for output as #f" print #f, "" print #f, "print #f,csvHead$" print #f, "" print #f, "WHILE #sql hasanswer()" print #f, " result$ = #sql nextrow$(q1$)" print #f, " print #f,q2$;result$;q2$" print #f, "WEND" print #f, "close #f" print #f, "wait" print #f, "" print #f, "' -------------------------------" print #f, "' Messages and error handling" print #f, "' -------------------------------" print #f, "[doMsg]" print #f, " html """"" print #f, "" print #f, " html """"" print #f, "" print #f, " html """"" print #f, "infoNum = 0" print #f, "wrnNum = 0" print #f, "errNum = 0" print #f, "'on error goto [handler]" print #f, "RETURN" print #f, "" print #f, "[handler]" print #f, "errNum = errNum + 1" print #f, "errMsg$(errNum) = ""Err number:"";Err;"" Description:"";Err$" print #f, "gosub [doMsg]" print #f, "'on error goto [handler1]" 'print #f, " #sql disconnect()" print #f, "'on error goto [handler]" print #f, "WAIT" print #f, "[handler1]" print #f, "'on error goto [handler]" print #f, "wait" print #f, "" print #f, "' ================================================" print #f, "' Signin - set keyUser and keyPass for user/pass" print #f, "' Normally done with a db user file" print #f, "' ================================================" print #f, "[doLogin]" print #f, "CLS" print #f, "loginCanMaint$ = ""N"" " print #f, "html bf$;""
" print #f, "" print #f, "
LOGIN
UserName"" " print #f, " TEXTBOX #userName, """" " print #f, "" print #f, "html ""
Password:""" print #f, "PasswordBox #passWord, """" " print #f, "" print #f, "html ""
""" print #f, "html bf$;""
""" print #f, "button #si, ""Signin"", [doSignin]" print #f, "html """"" print #f, "button #ex, ""Exit"", [";refTbl$;"List]" print #f, " #ex cssclass(""extBtn"")" print #f, "html ""
""" print #f, "html ""
""" print #f, "WAIT" print #f, "" print #f, "[doSignin]" print #f, "loginUserName$ = trim$(#userName contents$())" print #f, "loginPassWord$ = trim$(#passWord contents$())" print #f, "if (loginUserName$ = keyUser$) and (loginPassWord$ = keyPass$) then" print #f, " loginCanMaint$ = ""Y"" " print #f, " cls" print #f, " infoNum = infoNum + 1" print #f, " infoMsg$(infoNum) = ""Maintenance Privliges Granted"" " print #f, " goto [";refTbl$;"List]" print #f, " else" print #f, " loginCanMaint$ = ""N"" " print #f, " cls" print #f, " errNum = errNum + 1" print #f, " errMsg$(errNum) = ""Invalid Username Or Password"" " print #f, " goto [";refTbl$;"List]" print #f, "end if" print #f, "wait" print #f, "" print #f, "' -----------------------------------------" print #f, "' Get outta here" print #f, "' -----------------------------------------" print #f, "[doExit]" print #f, "" print #f, "html """"" print #f, "wait" print #f, "" print #f, "' -------------------------------------" print #f, "' help - please help me I can't get up" print #f, "' -------------------------------------" print #f, "[";refTbl$;"doHelp]" print #f, "cls" print #f, "numHelp = 11 ' set number of help items" print #f, "dim helpItem$(numHelp)" print #f, "if helpItem$(1) = """" then" print #f, "helpItem$(1) = ""[Add]|Use the [Add] or the [A]dd in the list to add a record""" print #f, "helpItem$(2) = ""[Sort]|You can sort in different sequences by selecting the field from the drop down list""" print #f, "helpItem$(3) = ""[Search]|This helps you find information. You can use any or all of them at once.""" print #f, "helpItem$(4) = ""[Exit]|Leave the system""" print #f, "helpItem$(5) = ""[Prev]|Go to the previous page""" print #f, "helpItem$(6) = ""Page Num|Enter a page number to go directly to that page. Then use [Next]""" print #f, "helpItem$(7) = ""[Next]|Go to the next page""" print #f, "helpItem$(8) = ""LPP|Set Lines Per Page. The default is 30""" print #f, "helpItem$(9) = ""[View]|View record detail""" print #f, "helpItem$(10) = ""[C]|Change a record""" print #f, "helpItem$(11) = ""[D]|Delete a record""" print #f, "end if" print #f, "html bf$;""
" print #f, "" print #f, "" print #f, """" print #f, "for i = 1 to numHelp" print #f, " hitm$ = word$(helpItem$(i),1,""|"")" print #f, " hdsc$ = word$(helpItem$(i),2,""|"")" print #f, " html """"" print #f, "next i" print #f, "html ""
ItemDescription
"";hitm$;"""";hdsc$;""
""" print #f, " button #ex, ""Return to List"", [";refTbl$;"List]" print #f, "html ""
""" print #f, "" print #f, "wait" print #f, "" print #f, "' -----------------------------------------" print #f, "' Convert single quotes to double quotes" print #f, "' -----------------------------------------" print #f, "FUNCTION dblQuote$(str$)" print #f, "i = 1" print #f, "qq$ = """" " print #f, "while (word$(str$,i,""'"")) <> """" " print #f, " dblQuote$ = dblQuote$;qq$;word$(str$,i,""'"")" print #f, " qq$ = ""''"" " print #f, " i = i + 1" print #f, "WEND" print #f, "END FUNCTION" print #f, "" print #f, "' --------------------------------" print #f, "' string replace rep str with" print #f, "' --------------------------------" print #f, "FUNCTION strRep$(str$,rep$,with$)" print #f, "ln = len(rep$)" print #f, "ln1 = ln - 1" print #f, "i = 1" print #f, "while i <= len(str$)" print #f, " if mid$(str$,i,ln) = rep$ then" print #f, " strRep$ = strRep$ + with$" print #f, " i = i + ln1" print #f, " else" print #f, " strRep$ = strRep$ + mid$(str$,i,1)" print #f, " end if" print #f, " i = i + 1" print #f, "WEND" print #f, "END FUNCTION" print #f, "" if ctlField$ <> "" then print #f, "" print #f, "' ------------------------------------------------------------------------------------" print #f, "' Find available record number" print #f, "' This does not always find the next number but finds holes in the numbers and uses it" print #f, "' Therefore, you never run out of numbers and you never need to reorganize the files" print #f, "' ------------------------------------------------------------------------------------" print #f, "FUNCTION useNum(ffile$,ffield$)" print #f, "useNum = 1" print #f, "sql$ = ""SELECT a."";ffield$;"" AS aa, c."";ffield$;"" AS cc,a."";ffield$;"" - 1 AS useNum" print #f, "FROM "";ffile$;"" AS a" print #f, "" print #f, "LEFT JOIN "";ffile$;"" as c" print #f, "ON c."";ffield$;"" = a."";ffield$;"" - 1" print #f, "WHERE c."";ffield$;"" is null" print #f, "AND a."";ffield$;"" > 1" print #f, "ORDER BY a."";ffield$;"" LIMIT 1""" print #f, "" print #f, "#sql execute(sql$)" print #f, "rows = #sql ROWCOUNT() 'Get the number of rows" print #f, "if rows > 0 then" print #f, "result$ = #sql nextrow$("" |"")" print #f, "aa = val(word$(result$,1,""|""))" print #f, "cc = val(word$(result$,2,""|""))" print #f, "useNum = val(word$(result$,3,""|""))" print #f, " else" print #f, " sql$ = ""SELECT max("";ffield$;"") as useNum FROM "";ffile$" print #f, " #sql execute(sql$)" print #f, " rows = #sql ROWCOUNT() 'Get the number of rows" print #f, " if rows > 0 then" print #f, " result$ = #sql nextrow$("" |"")" print #f, " useNum = val(word$(result$,1,""|"")) + 1" print #f, " end if" print #f, "end if" print #f, "END FUNCTION" end if print #f, "" print #f, "' -------------------------------------" print #f, "' Connect to Database" print #f, "' --------------------------------------" print #f, "[connectDb] ' Connect to the DB" print #f, "sqliteconnect #sql, ";refTbl$;"Db$ ' Connect to the DB" ' PRAGMA was used when RB had lock problems.. Probably not needed any longer 'print #f, "#sql execute(""PRAGMA journal_mode=WAL"")" 'print #f, "#sql execute(""PRAGMA locking_mode=NORMAL"")" 'print #f, "#sql execute(""PRAGMA synchronous=0"")" 'print #f, "#sql execute(""PRAGMA wal_autocheckpoint=0"")" 'print #f, "#sql execute(""PRAGMA cache_spill=0"")" 'print #f, "#sql execute(""PRAGMA journal_size_limit=0"")" print #f, "RETURN" print #f, "" if photoId$ <> "" then print #f, "' -------------------------------------" print #f, "' Popup for big midea" print #f, "' -------------------------------------" print #f, "[popImg]" print #f, "img$ = imgPath$ + EventKey$ ' Construct the full image path" print #f, "medId$ = EventKey$" print #f, "[media1]" print #f, "bigger = val(EventKey$) ' get media resized" print #f, "html """"" print #f, "html """"" print #f, "wait" print #f, "[closeBig] ' close big image" print #f, "html """"" print #f, "html """"" print #f, "wait" print #f, "" print #f, "' ---------------------------------------" print #f, "' media for video,photos, music" print #f, "' shows media with interface" print #f, "' supply " print #f, "' medId$ - the id of the media" print #f, "' impPath$ - the directory path where" print #f, "' media is located" print #f, "' mediaBig$ - ""Y"" for big media display" print #f, "' ---------------------------------------" print #f, "[media]" print #f, "if medId$ = """" then" print #f, " html ""None""" print #f, " RETURN" print #f, "end if" print #f, "b = 80" print #f, "if mediaBig$ = ""Y"" then b = 400" print #f, "if bigger <> 0 then b = bigger" print #f, "img$ = imgPath$;medId$" print #f, "ext$ = upper$(word$(medId$,2,"".""))" print #f, "if instr(""JPEG,JPG,PNG,GIF,SVG,WEBP,AVIF,BMP,ICO,APNG,SVG"",ext$) > 0 then ext$ = ""JPG""" print #f, "select case ext$" print #f, "case ""JPG""" print #f, " html """"" print #f, "case ""MP3""" print #f, " html """"" print #f, "case ""WAV""" print #f, " html """"" print #f, "case ""OGG""" print #f, " html """"" print #f, "case ""MPG""" print #f, " html """"" print #f, "case ""MP4""" print #f, " html """"" print #f, "case ""WEBM""" print #f, " html """"" print #f, "case ""PDF""" print #f, " if b = 0 then" print #f, " html """"" print #f, " else" print #f, " html """"" print #f, " end if" print #f, "case ""TXT""" print #f, " html """"" print #f, "case ""HTML""" print #f, " html """"" print #f, "case ""HTM""" print #f, " html """"" print #f, "case else" print #f, " html ""Unknown ext:"";ext$" print #f, "end select" print #f, "RETURN" end if print #f, "" print #f, "' -------------------------------------" print #f, "' set CSS" print #f, "' --------------------------------------" print #f, "SUB SetCSS" print #f, "" print #f, "CSSClass ""a.hdr"", ""{" print #f, " text-decoration: none;" print #f, " font-family: Arial, sans-serif;" print #f, " font-size: 15px;" print #f, " font-weight: bold;" print #f, " background-color: wheat;" print #f, " color: black;" print #f, " transition: background-color 0.3s ease;" print #f, "}"" " print #f, "" print #f, "CSSClass ""a.hdr:hover"", ""{" print #f, " background-color: green;" print #f, " color: red;" print #f, "}""" print #f, "" print #f, "CSSClass ""a.lBtn"", ""{" print #f, "Text-Align:Center;" print #f, "Border-Width:1px;" print #f, "Border-Style:solid;" print #f, "background:#FDDD8C;" print #f, "Border-Color:black;" print #f, "Font-Size:10pt;" print #f, "Font-Weight:Bold;" print #f, "Font-Family: Arial;" print #f, "Text-Decoration: None;" print #f, "}"" " print #f, "CSSClass ""a.sortHdr1"", ""{" print #f, "Text-Decoration: None;" print #f, "Color: red;" print #f, "}""" print #f, "CSSClass ""caption"",""{background-color:"";clrHdr$;""color:black;border:2px solid #000;font-weight: bold;}""" print #f, "CSSClass "".extBtn"", ""{background-color:pink;}""" print #f, "END SUB" close #f wait ' ------------------------------------------------------- ' get table info ' supply stbl$ = table name ' returns ' ------------------------------------------------------- [getTblInfo] snumFields = 0 scolNames$ = "" stblColNames$ = "" scolTypes$ = "" scolSizes$ = "" sqliteconnect #sql, dbFile$ ' Connect to the DB sql$ = "pragma table_info("+stbl$+")" #sql execute(sql$) snumFields = #sql ROWCOUNT() dim scolName$(snumFields +1) dim scolType$(snumFields +1) dim scolSize$(snumFields +1) for i = 1 to snumFields result$ = #sql nextrow$(" |") thisCol$ = word$(result$,2," |") scolName$(i) = thisCol$ scolNames$ = scolNames$ + thisCol$ + "," stblColNames$ = stblColNames$ + tbl$ + "." + thisCol$ + "," a$ = word$(result$,3," |") + "( )" scolType$(i) = word$(a$,1,"(") a$ = word$(a$,2,"(") a$ = word$(a$,1,")") scolSize$(i) = strRep$(a$,",",".") ' print i;" ";result$;"->";scolName$(i);":";scolType$(i);":";scolSize$(i) next i if ctlField$ = "rowid" then snumFields = snumFields +1 scolName$(snumFields) = "rowid" scolType$(snumFields) = "int" scolSize$(snumFields) = "6" end if RETURN ' ------------------------------------------- ' need fld$ ' returns thisTypeVal$ [I]nteger or [C]har ' ------------------------------------------- [getTypeVal] bField$ = " " + trim$(fld$) + " " t3$ = word$(t2$,2,bField$) t3$ = word$(t3$,1,",") t4$ = word$(t3$,2,"(") thisLen = val(word$(t4$,1,")")) thisLen = min(thisLen,60) 'print fld$;" t3:";t3$;" t4:";t4$;" thisLen:";thisLen if thisLen = 0 then thisLen$ = "16" else thisLen$ = str$(thisLen) end if thisType$ = upper$(word$(t3$,1," ")) thisType$ = word$(thisType$,1,")") thisTypeVal$ = "" 'print "thisType:";thisType$;" thisTypeVal:";thisTypeVal$ for ii = 1 to 28 if thisType$ = type$(ii) then thisTypeVal$ = typeVal$(ii) goto [getTypeEnd] end if next ii [getTypeEnd] if thisTypeVal$ = "DT" then thisLen$ = "19" if thisTypeVal$ = "D" then thisLen$ = "17" if thisTypeVal$ = "T" then thisLen$ = "200" if thisTypeVal$ = "TI" then thisLen$ = "8" thisLen = val(thisLen$) 'print "================= t3:";bField$;"|";t3$;"|len:";thisLen$;" thisTyp:";thisType$;" typ:";thisTypeVal$ RETURN ' -------------------------------- ' string replace rep str with ' -------------------------------- FUNCTION strRep$(str$,rep$,with$) ln = len(rep$) ln1 = ln - 1 i = 1 while i <= len(str$) if mid$(str$,i,ln) = rep$ then strRep$ = strRep$ + with$ i = i + ln1 else strRep$ = strRep$ + mid$(str$,i,1) end if i = i + 1 WEND END FUNCTION ' ----------------------------------------- ' strip junk ' ----------------------------------------- FUNCTION strip$(str$) strip$ = "" for i = 1 to len(str$) a$ = MID$(str$,i,1) a = ASC(a$) if a > 31 then if a < 127 then if a$ <> "'" then if a$ <> """" then strip$ = strip$ + a$ end if end if end if end if next i END FUNCTION ' ----------------------------------------------------------- ' break on Caps.. ItemNum becomes 2 lines of Item Num ' ----------------------------------------------------------- FUNCTION hdrBreak$(a$) for i = 1 to len(a$) a1$ = mid$(a$,i,1) a2$ = mid$(a$,i+1,1) a11$ = lower$(a1$) a22$ = lower$(a2$) hdrBreak$ = hdrBreak$ + a1$ if a22$ <> a2$ and a11$ = a1$ then hdrBreak$ = hdrBreak$ + """+cr$+""" next i END FUNCTION [sqlErr] errNum = errNum + 1 errMsg$(errNum) = "sql Error:";sql$ goto [main] wait ' ----------------------------- ' Error Handler ' ----------------------------- [errFile] errNum = errNum + 1 errMsg$(errNum) = "Data base master file error:";sqliteDb$ gosub [doMsg] wait [errSQL1] errNum = errNum + 1 errMsg$(errNum) = "sqlError:";sql1$ gosub [doMsg] #sql1 disconnect() wait [errDbFile] errNum = errNum + 1 errMsg$(errNum) = "File:";dbFile$;" does not exist" gosub [doMsg] wait [doMsg] if infoNum > 0 then html "" end if if wrnNum > 0 then html "" end if if errNum > 0 then html "" end if infoNum = 0 wrnNum = 0 errNum = 0 'on error goto [handler] RETURN [handler] html "" 'on error goto [handler] WAIT ' ----------------------------------------- ' Get outta here ' ----------------------------------------- [doExit] html ""