-- Contacts application for Rockbox written in LUA -- Licensed under GPLv2 or, at your choice, any later version. -- Coded by Gabriel Maia (gbl08ma). Email: admin [at] g.ro.lt -------------------------------------------------------------------------------- -- Libraries and helper functions not writen for this plugin -- Terms for each library are available on the comments before each library. --[[ Save Table to File/Stringtable Load Table from File/Stringtable v 0.94 Lua 5.1 compatible Userdata and indices of these are not saved Functions are saved via string.dump, so make sure it has no upvalues References are saved ---------------------------------------------------- table.save( table [, filename] ) Saves a table so it can be called via the table.load function again table must a object of type 'table' filename is optional, and may be a string representing a filename or true/1 table.save( table ) on success: returns a string representing the table (stringtable) (uses a string as buffer, ideal for smaller tables) table.save( table, true or 1 ) on success: returns a string representing the table (stringtable) (uses io.tmpfile() as buffer, ideal for bigger tables) table.save( table, "filename" ) on success: returns 1 (saves the table to file "filename") on failure: returns as second argument an error msg ---------------------------------------------------- table.load( filename or stringtable ) Loads a table that has been saved via the table.save function on success: returns a previously saved table on failure: returns as second argument an error msg ---------------------------------------------------- chillcode, http://lua-users.org/wiki/SaveTableToFile Licensed under the same terms as Lua itself. ]]-- do -- declare local variables --// exportstring( string ) --// returns a "Lua" portable version of the string local function exportstring( s ) s = string.format( "%q",s ) -- to replace s = string.gsub( s,"\\\n","\\n" ) s = string.gsub( s,"\r","\\r" ) s = string.gsub( s,string.char(26),"\"..string.char(26)..\"" ) return s end --// The Save Function function table.save( tbl,filename ) local charS,charE = " ","\n" local file,err -- create a pseudo file that writes to a string and return the string if not filename then file = { write = function( self,newstr ) self.str = self.str..newstr end, str = "" } charS,charE = "","" -- write table to tmpfile elseif filename == true or filename == 1 then charS,charE,file = "","",io.tmpfile() -- write table to file -- use io.open here rather than io.output, since in windows when clicking on a file opened with io.output will create an error else file,err = io.open( filename, "w" ) if err then return _,err end end -- initiate variables for save procedure local tables,lookup = { tbl },{ [tbl] = 1 } file:write( "return {"..charE ) for idx,t in ipairs( tables ) do if filename and filename ~= true and filename ~= 1 then file:write( "-- Table: {"..idx.."}"..charE ) end file:write( "{"..charE ) local thandled = {} for i,v in ipairs( t ) do thandled[i] = true -- escape functions and userdata if type( v ) ~= "userdata" then -- only handle value if type( v ) == "table" then if not lookup[v] then table.insert( tables, v ) lookup[v] = #tables end file:write( charS.."{"..lookup[v].."},"..charE ) elseif type( v ) == "function" then file:write( charS.."loadstring("..exportstring(string.dump( v )).."),"..charE ) else local value = ( type( v ) == "string" and exportstring( v ) ) or tostring( v ) file:write( charS..value..","..charE ) end end end for i,v in pairs( t ) do -- escape functions and userdata if (not thandled[i]) and type( v ) ~= "userdata" then -- handle index if type( i ) == "table" then if not lookup[i] then table.insert( tables,i ) lookup[i] = #tables end file:write( charS.."[{"..lookup[i].."}]=" ) else local index = ( type( i ) == "string" and "["..exportstring( i ).."]" ) or string.format( "[%d]",i ) file:write( charS..index.."=" ) end -- handle value if type( v ) == "table" then if not lookup[v] then table.insert( tables,v ) lookup[v] = #tables end file:write( "{"..lookup[v].."},"..charE ) elseif type( v ) == "function" then file:write( "loadstring("..exportstring(string.dump( v )).."),"..charE ) else local value = ( type( v ) == "string" and exportstring( v ) ) or tostring( v ) file:write( value..","..charE ) end end end file:write( "},"..charE ) end file:write( "}" ) -- Return Values -- return stringtable from string if not filename then -- set marker for stringtable return file.str.."--|" -- return stringttable from file elseif filename == true or filename == 1 then file:seek ( "set" ) -- no need to close file, it gets closed and removed automatically -- set marker for stringtable return file:read( "*a" ).."--|" -- close file and return 1 else file:close() return 1 end end --// The Load Function function table.load( sfile ) -- catch marker for stringtable if string.sub( sfile,-3,-1 ) == "--|" then tables,err = loadstring( sfile ) else tables,err = loadfile( sfile ) end if err then return _,err end tables = tables() for idx = 1,#tables do local tolinkv,tolinki = {},{} for i,v in pairs( tables[idx] ) do if type( v ) == "table" and tables[v[1]] then table.insert( tolinkv,{ i,tables[v[1]] } ) end if type( i ) == "table" and tables[i[1]] then table.insert( tolinki,{ i,tables[i[1]] } ) end end -- link values, first due to possible changes of indices for _,v in ipairs( tolinkv ) do tables[idx][v[1]] = v[2] end -- link indices for _,v in ipairs( tolinki ) do tables[idx][v[2]],tables[idx][v[1]] = tables[idx][v[1]],nil end end return tables[1] end -- close do end -------------------------------------------------------------------------------- -- END OF LIBRARIES -- -- Global settings and variables: db_file = "/contacts.txt" -------------------------------------------------------------------------------- -- Helper functions: -- Return true if file exists and is readable. function file_exists(path) local file = io.open(path, "rb") if file then file:close() end return file ~= nil end -------------------------------------------------------------------------------- -- Contacts database I/O functions: contacts = {{}} totalentries = 0 -- Each contact entry contains these fields: -- first ------------> first name -- middle -----------> middle name -- last -------------> last name -- jobtitle ---------> job title -- department -------> department -- company ----------> company -- worktel ----------> work phone number -- workfax ----------> work fax number -- workaddr ---------> work address -- im ---------------> instant messaging account -- email ------------> personal email -- mobiletel --------> personal mobile phone number -- webpage ----------> personal web page -- officeloc --------> office location -- hometel ----------> home phone number -- homeaddr ---------> home address -- category ---------> contact category (for a future order-by-category view) -- otheraddr --------> other address -- pager ------------> pager -- cartel -----------> car phone number -- homefax ----------> home fax number -- companytel -------> company phone number -- work2tel ---------> 2nd work phone number -- home2tel ---------> 2nd home phone number -- radiotel ---------> radio phone number -- im2 --------------> 2nd instant messaging account -- im3 --------------> 3rd instant messaging account -- email2 -----------> 2nd email address -- assistant --------> assistant name -- assistanttel -----> assistant phone number -- manager ----------> manager name -- govtid -----------> government ID -- account ----------> some account -- customerid -------> customer ID -- birthday ---------> birthday (DD-MM-YYYY, by this order and including the '-'s) -- anniversary ------> anniversary (DD-MM-YYYY, by this order and including the '-'s) -- spouse -----------> spouse name -- children ---------> children name -- notes ------------> a free, simple text field for storing anything else -- -- you can call add_contact without specifying all these arguments, for instance -- if you only must save 'first', 'middle', 'last' and 'jobtitle' arguments you -- can do like this: -- -- add_contact_to_db("First", "Middle", "Last", "Dr.") -- -- but, if you want to save 'first', 'last' and 'worktel', but others are empty, -- you must add empty arguments until 'worktel' and between 'first' and last', -- like this: -- -- add_contact_to_db("First", "", "Last", "", "", "", "8965854") function add_contact_to_db(first, middle, last, jobtitle, department, company, worktel, workfax, workaddr, im, email, mobiletel, webpage, officeloc, hometel, homeaddr, category, otheraddr, pager, cartel, homefax, companytel, work2tel, home2tel, radiotel, im2, im3, email2, assistant, assistanttel, manager, govtid, account, customerid, birthday, anniversary, spouse, children, notes) totalentries = totalentries + 1 -- contact was added contactid = {} -- creates a table inside the main contacts table if first ~= nil then contactid.first = first end if middle ~= nil then contactid.middle = middle end if last ~= nil then contactid.last = last end if jobtitle ~= nil then contactid.jobtitle = jobtitle end if department ~= nil then contactid.department = department end if company ~= nil then contactid.company = company end if worktel ~= nil then contactid.worktel = worktel end if workfax ~= nil then contactid.workfax = workfax end if workaddr ~= nil then contactid.workaddr = workaddr end if im ~= nil then contactid.im = im end if email ~= nil then contactid.email = email end if mobiletel ~= nil then contactid.mobiletel = mobiletel end if webpage ~= nil then contactid.webpage = webpage end if officeloc ~= nil then contactid.officeloc = officeloc end if hometel ~= nil then contactid.hometel = hometel end if homeaddr ~= nil then contactid.homeaddr = homeaddr end if category ~= nil then contactid.category = category end if otheraddr ~= nil then contactid.otheraddr = otheraddr end if pager ~= nil then contactid.pager = pager end if cartel ~= nil then contactid.cartel = cartel end if homefax ~= nil then contactid.homefax = homefax end if companytel ~= nil then contactid.companytel = companytel end if work2tel ~= nil then contactid.work2tel = work2tel end if home2tel ~= nil then contactid.home2tel = home2tel end if radiotel ~= nil then contactid.radiotel = radiotel end if im2 ~= nil then contactid.im2 = im2 end if im3 ~= nil then contactid.im3 = im3 end if email2 ~= nil then contactid.email2 = email2 end if assistant ~= nil then contactid.assistant = assistant end if assistanttel ~= nil then contactid.assistanttel = assistanttel end if manager ~= nil then contactid.manager = manager end if govtid ~= nil then contactid.govtid = govtid end if account ~= nil then contactid.account = account end if customerid ~= nil then contactid.customerid = customerid end if birthday ~= nil then contactid.birthday = birthday end if anniversary ~= nil then contactid.anniversary = anniversary end if spouse ~= nil then contactid.spouse = spouse end if children ~= nil then contactid.children = children end if notes ~= nil then contactid.notes = notes end table.insert(contacts, contactid) end -- the following function deletes a contact from the database, given its contactid function delete_contact_from_db (contactindex) table.remove(contacts, contactindex) totalentries = totalentries - 1 end -- Saves the database to its file function save_db () table.save(contacts, db_file) end -- Loads the database from its file and stores it on the contacts table function load_db () if file_exists(db_file) == true then -- only load the file if it exists contacts = table.load(db_file) -- update the total of entries count: for i,v in ipairs(contacts) do totalentries = totalentries + 1 end totalentries = totalentries - 1 -- it always adds one more table: the index -- it doesn't get in the stats so it's removed here else contacts = {{}} totalentries = 0 end end -- Helper function to convert the code name of a contact field into human -- readable name (e.g. "newim3" to "3rd Instant Messaging Account") function HumanizeFieldName(codename) if codename == "first" then return "First Name" end if codename == "middle" then return "Middle Name" end if codename == "last" then return "Last Name" end if codename == "jobtitle" then return "Job Title" end if codename == "department" then return "Department" end if codename == "company" then return "Company" end if codename == "worktel" then return "Work phone number" end if codename == "workfax" then return "Work address" end if codename == "workaddr" then return "Instant Messaging Acccount" end if codename == "im" then return "Personal Email Address" end if codename == "email" then return "Personal Email Address" end if codename == "mobiletel" then return "Personal Mobile Phone Number" end if codename == "webpage" then return "Personal Web Page" end if codename == "officeloc" then return "Office location" end if codename == "hometel" then return "Home phone number" end if codename == "homeaddr" then return "Home address" end if codename == "category" then return "Category" end if codename == "otheraddr" then return "Other address" end if codename == "pager" then return "Pager" end if codename == "cartel" then return "Car phone number" end if codename == "homefax" then return "Home fax number" end if codename == "companytel" then return "Company phone number" end if codename == "work2tel" then return "2nd work phone number" end if codename == "home2tel" then return "2nd home phone number" end if codename == "radiotel" then return "Radio phone number" end if codename == "im2" then return "2nd Instant Messaging Account" end if codename == "im3" then return "3rd Instant Messaging Account" end if codename == "email2" then return "2nd Email Address" end if codename == "assistant" then return "Assistant" end if codename == "assistanttel" then return "Assistant phone number" end if codename == "manager" then return "Manager" end if codename == "govtid" then return "Government ID" end if codename == "account" then return "Account" end if codename == "customerid" then return "Customer ID" end if codename == "birthday" then return "Birthday" end if codename == "anniversary" then return "Anniversary" end if codename == "spouse" then return "Spouse" end if codename == "children" then return "Children" end if codename == "notes" then return "Notes" end end function ShowMainMenu() -- the menu will contain the first, middle and last name of the contacts -- when people select the contact, it will show the other details mainmenu = {} -- add possible action at top of menu table.insert(mainmenu, "!! Add contact (or press Play)") if file_exists(db_file) then for i,v in ipairs(contacts) do if contacts[i].first ~= nil and contacts[i].middle ~= nil and contacts[i].last ~= nil then table.insert(mainmenu, contacts[i].first .. " " .. contacts[i].middle .. " " .. contacts[i].last) end end end while true do -- don't exit of program until user selects Exit s = rb.do_menu("Contacts | Total entries: " .. totalentries, mainmenu, nil, false) if s == -2 or s == -1 then save_db() os.exit() elseif s == -4 or s == 0 then ShowAddContactScreen() else ShowContactScreen(s + 1) -- tablepos starts at 1, but 1 is the table index. -- s is zero-based. -- the fact that the first menu item returns a s of 0 isn't a problem as -- this code will only be run when s =< 1 (when s == 0 user chose to add -- a contact) -- practical example: user selects the first contact of the list. do_menu -- returns a value of 1 and the tablepos for that contact is 2. So, tablepos -- is equal to s + 1 end end end function ShowAddContactScreen() -- this screen is a menu that allows users to add a new contact. -- Each field is shown as an menu item, and when user selects that field, -- a virtual keyboard will show so they can input that field's content. -- The screen will be close when user saves the contact or cancels. -- declare variables for each fields of the new contact newfirst = "" newmiddle = "" newlast = "" newjobtitle = "" newdepartment = "" newcompany = "" newworktel = "" newworkfax = "" newworkaddr = "" newim = "" newemail = "" newmobiletel = "" newwebpage = "" newofficeloc = "" newhometel = "" newhomeaddr = "" newcategory = "" newotheraddr = "" newpager = "" newcartel = "" newhomefax = "" newcompanytel = "" newwork2tel = "" newhome2tel = "" newradiotel = "" newim2 = "" newim3 = "" newemail2 = "" newassistant = "" newassistanttel = "" newmanager = "" newgovtid = "" newaccount = "" newcustomerid = "" newbirthday = "" newanniversary = "" newspouse = "" newchildren = "" newnotes = "" while true do -- it will need to clear the old menu and draw a new one every -- time the user changes a field addcontmenu = {} -- add possible actions at the top of the menu table.insert(addcontmenu, "!! Save new contact (or press Play)") -- index 0 table.insert(addcontmenu, "!! Cancel (or press Menu)") -- index 1 -- add a contact entry for each field table.insert(addcontmenu, "First Name" .. ": " .. newfirst) -- index 2 table.insert(addcontmenu, "Middle Name" .. ": " .. newmiddle) -- index 3 table.insert(addcontmenu, "Last Name" .. ": " .. newlast) -- index 4 table.insert(addcontmenu, "Job Title" .. ": " .. newjobtitle) -- index 5 table.insert(addcontmenu, "Department" .. ": " .. newdepartment) -- index 6 table.insert(addcontmenu, "Company" .. ": " .. newcompany) -- index 7 table.insert(addcontmenu, "Work phone number" .. ": " .. newworktel) -- index 8 table.insert(addcontmenu, "Work fax number" .. ": " .. newworkfax) -- index 9 table.insert(addcontmenu, "Work address" .. ": " .. newworkaddr) -- index 10 table.insert(addcontmenu, "Instant Messaging Acccount" .. ": " .. newim) -- index 11 table.insert(addcontmenu, "Personal Email Address" .. ": " .. newemail) -- index 12 table.insert(addcontmenu, "Personal Mobile Phone Number" .. ": " .. newmobiletel) -- index 13 table.insert(addcontmenu, "Personal Web Page" .. ": " .. newwebpage) -- index 14 table.insert(addcontmenu, "Office location" .. ": " .. newofficeloc) -- index 15 table.insert(addcontmenu, "Home phone number" .. ": " .. newhometel) -- index 16 table.insert(addcontmenu, "Home address" .. ": " .. newhomeaddr) -- index 17 table.insert(addcontmenu, "Category" .. ": " .. newcategory) -- index 18 table.insert(addcontmenu, "Other address" .. ": " .. newotheraddr) -- index 19 table.insert(addcontmenu, "Pager" .. ": " .. newpager) -- index 20 table.insert(addcontmenu, "Car phone number" .. ": " .. newcartel) -- index 21 table.insert(addcontmenu, "Home fax number" .. ": " .. newhomefax) -- index 22 table.insert(addcontmenu, "Company phone number" .. ": " .. newcompanytel) -- index 23 table.insert(addcontmenu, "2nd work phone number" .. ": " .. newwork2tel) -- index 24 table.insert(addcontmenu, "2nd home phone number" .. ": " .. newhome2tel) -- index 25 table.insert(addcontmenu, "Radio phone number" .. ": " .. newradiotel) -- index 26 table.insert(addcontmenu, "2nd Instant Messaging Account" .. ": " .. newim2) -- index 27 table.insert(addcontmenu, "3rd Instant Messaging Account" .. ": " .. newim3) -- index 28 table.insert(addcontmenu, "2nd Email Address" .. ": " .. newemail2) -- index 29 table.insert(addcontmenu, "Assistant" .. ": " .. newassistant) -- index 30 table.insert(addcontmenu, "Assistant phone number" .. ": " .. newassistanttel) -- index 31 table.insert(addcontmenu, "Manager" .. ": " .. newmanager) -- index 32 table.insert(addcontmenu, "Government ID" .. ": " .. newgovtid) -- index 33 table.insert(addcontmenu, "Account" .. ": " .. newaccount) -- index 34 table.insert(addcontmenu, "Customer ID" .. ": " .. newcustomerid) -- index 35 table.insert(addcontmenu, "Birthday" .. ": " .. newbirthday) -- index 36 table.insert(addcontmenu, "Anniversary" .. ": " .. newanniversary) -- index 37 table.insert(addcontmenu, "Spouse" .. ": " .. newspouse) -- index 38 table.insert(addcontmenu, "Children" .. ": " .. newchildren) -- index 39 table.insert(addcontmenu, "Notes" .. ": " .. newnotes) -- index 40 -- actually draw the menu s = rb.do_menu("Add contact", addcontmenu, nil, false) if s == -1 or s == 1 or s == -2 then ShowMainMenu() -- user selected to cancel, discard elseif s == -4 or s == 0 then -- save contact and go back to main menu add_contact_to_db(newfirst, newmiddle, newlast, newjobtitle, newdepartment, newcompany, newworktel, newworkfax, newworkaddr, newim, newemail, newmobiletel, newwebpage, newofficeloc, newhometel, newhomeaddr, newcategory, newotheraddr, newpager, newcartel, newhomefax, newcompanytel, newwork2tel, newhome2tel, newradiotel, newim2, newim3, newemail2, newassistant, newassistanttel, newmanager, newgovtid, newaccount, newcustomerid, newbirthday, newanniversary, newspouse, newchildren, newnotes) rb.splash(rb.HZ, "Contact saved") ShowMainMenu() -- now starts the repetitive code of opening a keyboard for each field and -- when user is done, save the input to a buffer elseif s == 2 then newfirst = rb.kbd_input(newfirst, string.len(newfirst)) elseif s == 3 then newmiddle = rb.kbd_input(newmiddle, string.len(newmiddle)) elseif s == 4 then newlast = rb.kbd_input(newlast, string.len(newlast)) elseif s == 5 then newjobtitle = rb.kbd_input(newjobtitle, string.len(newjobtitle)) elseif s == 6 then newdepartment = rb.kbd_input(newdepartment, string.len(newdepartment)) elseif s == 7 then newcompany = rb.kbd_input(newcompany, string.len(newcompany)) elseif s == 8 then newworktel = rb.kbd_input(newworktel, string.len(newworktel)) elseif s == 9 then newworkfax = rb.kbd_input(newworkfax, string.len(newworkfax)) elseif s == 10 then newworkaddr = rb.kbd_input(newworkaddr, string.len(newworkaddr)) elseif s == 11 then newim = rb.kbd_input(newim, string.len(newim)) elseif s == 12 then newemail = rb.kbd_input(newemail, string.len(newemail)) elseif s == 13 then newmobiletel = rb.kbd_input(newmobiletel, string.len(newmobiletel)) elseif s == 14 then newwebpage = rb.kbd_input(newwebpage, string.len(newwebpage)) elseif s == 15 then newofficeloc = rb.kbd_input(newofficeloc, string.len(newofficeloc)) elseif s == 16 then newhometel = rb.kbd_input(newhometel, string.len(newhometel)) elseif s == 17 then newhomeaddr = rb.kbd_input(newhomeaddr, string.len(newhomeaddr)) elseif s == 18 then newcategory = rb.kbd_input(newcategory, string.len(newcategory)) elseif s == 19 then newotheraddr = rb.kbd_input(newotheraddr, string.len(newotheraddr)) elseif s == 20 then newpager = rb.kbd_input(newpager, string.len(newpager)) elseif s == 21 then newcartel = rb.kbd_input(newcartel, string.len(newcartel)) elseif s == 22 then newhomefax = rb.kbd_input(newhomefax, string.len(newhomefax)) elseif s == 23 then newcompanytel = rb.kbd_input(newcompanytel, string.len(newcompanytel)) elseif s == 24 then newwork2tel = rb.kbd_input(newwork2tel, string.len(newwork2tel)) elseif s == 25 then newhome2tel = rb.kbd_input(newhome2tel, string.len(newhome2tel)) elseif s == 26 then newradiotel = rb.kbd_input(newradiotel, string.len(newradiotel)) elseif s == 27 then newim2 = rb.kbd_input(newim2, string.len(newim2)) elseif s == 28 then newim3 = rb.kbd_input(newlast, string.len(newim3)) elseif s == 29 then newemail2 = rb.kbd_input(newemail2, string.len(newemail2)) elseif s == 30 then newassistant = rb.kbd_input(newassistant, string.len(newassistant)) elseif s == 31 then newassistanttel = rb.kbd_input(newassistanttel, string.len(newassistanttel)) elseif s == 32 then newmanager = rb.kbd_input(newmanager, string.len(newmanager)) elseif s == 33 then newgovtid = rb.kbd_input(newgovtid, string.len(newgovtid)) elseif s == 34 then newaccount = rb.kbd_input(newaccount, string.len(newaccount)) elseif s == 35 then newcustomerid = rb.kbd_input(newcustomerid, string.len(newcustomerid)) elseif s == 36 then newbirthday = rb.kbd_input(newbirthday, string.len(newbirthday)) elseif s == 37 then newanniversary = rb.kbd_input(newanniversary, string.len(newanniversary)) elseif s == 38 then newspouse = rb.kbd_input(newspouse, string.len(newspouse)) elseif s == 39 then newchildren = rb.kbd_input(newchildren, string.len(newchildren)) elseif s == 40 then newnotes = rb.kbd_input(newnotes, string.len(newnotes)) else rb.splash(2 * rb.HZ, "Error! Selected index: " .. s) end end end function ShowContactScreen(tablepos) -- this screen is a menu that allows users to view the information on a contact. -- Each field is shown as an menu item, and when user selects that field, -- another screen will show up so the user can see the full field (e.g. when -- it's too long. On that screen, the user is also able to choose to edit that -- field or clear it. -- tablepos: position in contacts table while true do contmenu = {} -- add possible actions at the top of the menu table.insert(contmenu, "Return to contacts list") -- index 0 table.insert(contmenu, "Edit contact (or press Play)") -- index 1 table.insert(contmenu, "Delete contact") -- index 2 -- add a viewer entry for each field table.insert(contmenu, "First Name" .. ": " .. contacts[tablepos].first) -- index 3 table.insert(contmenu, "Middle Name" .. ": " .. contacts[tablepos].middle) -- index 4 table.insert(contmenu, "Last Name" .. ": " .. contacts[tablepos].last) -- index 5 table.insert(contmenu, "Job Title" .. ": " .. contacts[tablepos].jobtitle) -- index 6 table.insert(contmenu, "Department" .. ": " .. contacts[tablepos].department) -- index 7 table.insert(contmenu, "Company" .. ": " .. contacts[tablepos].company) -- index 8 table.insert(contmenu, "Work phone number" .. ": " .. contacts[tablepos].worktel) -- index 9 table.insert(contmenu, "Work fax number" .. ": " .. contacts[tablepos].workfax) -- index 10 table.insert(contmenu, "Work address" .. ": " .. contacts[tablepos].workaddr) -- index 11 table.insert(contmenu, "Instant Messaging Acccount" .. ": " .. contacts[tablepos].im) -- index 12 table.insert(contmenu, "Personal Email Address" .. ": " .. contacts[tablepos].email) -- index 13 table.insert(contmenu, "Personal Mobile Phone Number" .. ": " .. contacts[tablepos].mobiletel) -- index 14 table.insert(contmenu, "Personal Web Page" .. ": " .. contacts[tablepos].webpage) -- index 15 table.insert(contmenu, "Office location" .. ": " .. contacts[tablepos].officeloc) -- index 16 table.insert(contmenu, "Home phone number" .. ": " .. contacts[tablepos].hometel) -- index 17 table.insert(contmenu, "Home address" .. ": " .. contacts[tablepos].homeaddr) -- index 18 table.insert(contmenu, "Category" .. ": " .. contacts[tablepos].category) -- index 19 table.insert(contmenu, "Other address" .. ": " .. contacts[tablepos].otheraddr) -- index 20 table.insert(contmenu, "Pager" .. ": " .. contacts[tablepos].pager) -- index 21 table.insert(contmenu, "Car phone number" .. ": " .. contacts[tablepos].cartel) -- index 22 table.insert(contmenu, "Home fax number" .. ": " .. contacts[tablepos].homefax) -- index 23 table.insert(contmenu, "Company phone number" .. ": " .. contacts[tablepos].companytel) -- index 24 table.insert(contmenu, "2nd work phone number" .. ": " .. contacts[tablepos].work2tel) -- index 25 table.insert(contmenu, "2nd home phone number" .. ": " .. contacts[tablepos].home2tel) -- index 26 table.insert(contmenu, "Radio phone number" .. ": " .. contacts[tablepos].radiotel) -- index 27 table.insert(contmenu, "2nd Instant Messaging Account" .. ": " .. contacts[tablepos].im2) -- index 28 table.insert(contmenu, "3rd Instant Messaging Account" .. ": " .. contacts[tablepos].im3) -- index 29 table.insert(contmenu, "2nd Email Address" .. ": " .. contacts[tablepos].email2) -- index 30 table.insert(contmenu, "Manager" .. ": " .. contacts[tablepos].manager) -- index 31 table.insert(contmenu, "Assistant" .. ": " .. contacts[tablepos].assistant) -- index 32 table.insert(contmenu, "Assistant phone number" .. ": " .. contacts[tablepos].assistanttel) -- index 33 table.insert(contmenu, "Government ID" .. ": " .. contacts[tablepos].govtid) -- index 34 table.insert(contmenu, "Account" .. ": " .. contacts[tablepos].account) -- index 35 table.insert(contmenu, "Customer ID" .. ": " .. contacts[tablepos].customerid) -- index 36 table.insert(contmenu, "Birthday" .. ": " .. contacts[tablepos].birthday) -- index 37 table.insert(contmenu, "Anniversary" .. ": " .. contacts[tablepos].anniversary) -- index 38 table.insert(contmenu, "Spouse" .. ": " .. contacts[tablepos].spouse) -- index 39 table.insert(contmenu, "Children" .. ": " .. contacts[tablepos].children) -- index 40 table.insert(contmenu, "Notes" .. ": " .. contacts[tablepos].notes) -- index 41 -- actually draw the menu s = rb.do_menu("View contact", contmenu, nil, false) if s == -1 or s == -2 or s == 0 then ShowMainMenu() -- user selected to go back to contacts list elseif s == -4 or s == 1 then -- edit full contact rb.splash(rb.HZ, "In development...") elseif s == 2 then -- delete contact delete_contact_from_db(tablepos) rb.splash(rb.HZ, "Contact deleted") ShowMainMenu() else -- user selected one of the fields, show dedicated field screen if s == 3 then ShowFieldScreen(tablepos, "first") end if s == 4 then ShowFieldScreen(tablepos, "middle") end if s == 5 then ShowFieldScreen(tablepos, "last") end if s == 6 then ShowFieldScreen(tablepos, "jobtitle") end if s == 7 then ShowFieldScreen(tablepos, "department") end if s == 8 then ShowFieldScreen(tablepos, "company") end if s == 9 then ShowFieldScreen(tablepos, "worktel") end if s == 10 then ShowFieldScreen(tablepos, "workfax") end if s == 11 then ShowFieldScreen(tablepos, "workaddr") end if s == 12 then ShowFieldScreen(tablepos, "im") end if s == 13 then ShowFieldScreen(tablepos, "email") end if s == 14 then ShowFieldScreen(tablepos, "mobiletel") end if s == 15 then ShowFieldScreen(tablepos, "webpage") end if s == 16 then ShowFieldScreen(tablepos, "officeloc") end if s == 17 then ShowFieldScreen(tablepos, "hometel") end if s == 18 then ShowFieldScreen(tablepos, "homeaddr") end if s == 19 then ShowFieldScreen(tablepos, "category") end if s == 20 then ShowFieldScreen(tablepos, "otheraddr") end if s == 21 then ShowFieldScreen(tablepos, "pager") end if s == 22 then ShowFieldScreen(tablepos, "cartel") end if s == 23 then ShowFieldScreen(tablepos, "homefax") end if s == 24 then ShowFieldScreen(tablepos, "companytel") end if s == 25 then ShowFieldScreen(tablepos, "work2tel") end if s == 26 then ShowFieldScreen(tablepos, "home2tel") end if s == 27 then ShowFieldScreen(tablepos, "radiotel") end if s == 28 then ShowFieldScreen(tablepos, "im2") end if s == 29 then ShowFieldScreen(tablepos, "im3") end if s == 30 then ShowFieldScreen(tablepos, "email2") end if s == 31 then ShowFieldScreen(tablepos, "manager") end if s == 32 then ShowFieldScreen(tablepos, "assistant") end if s == 33 then ShowFieldScreen(tablepos, "assistanttel") end if s == 34 then ShowFieldScreen(tablepos, "govtid") end if s == 35 then ShowFieldScreen(tablepos, "account") end if s == 36 then ShowFieldScreen(tablepos, "customerid") end if s == 37 then ShowFieldScreen(tablepos, "birthday") end if s == 38 then ShowFieldScreen(tablepos, "anniversary") end if s == 39 then ShowFieldScreen(tablepos, "spouse") end if s == 40 then ShowFieldScreen(tablepos, "children") end if s == 41 then ShowFieldScreen(tablepos, "notes") end end end end function ShowFieldScreen(tablepos, contactfield) -- this screen is a menu that allows users to view the information on a contact. -- Each field is shown as an menu item, and when user selects that field, -- another screen will show up so the user can see the full field (e.g. when -- it's too long. On that screen, the user is also able to choose to edit that -- field or clear it. -- tablepos: position in contacts table -- contactfield: string containing the name of the field accoring to the -- documentation on the add_contact_to_db function while true do fieldmenu = {} -- add possible actions at the top of the menu table.insert(fieldmenu, "Return to contact view") -- index 0 table.insert(fieldmenu, "Edit field (or press Play)") -- index 1 table.insert(fieldmenu, "Clear field") -- index 2 -- add information at the top of the menu table.insert(fieldmenu, "Contents of " .. HumanizeFieldName(contactfield) .. " below:") -- index 3 -- add a entry for the field content - index 4 if contactfield == "first" then table.insert(fieldmenu, contacts[tablepos].first) end if contactfield == "middle" then table.insert(fieldmenu, contacts[tablepos].middle) end if contactfield == "last" then table.insert(fieldmenu, contacts[tablepos].last) end if contactfield == "jobtitle" then table.insert(fieldmenu, contacts[tablepos].jobtitle) end if contactfield == "department" then table.insert(fieldmenu, contacts[tablepos].department) end if contactfield == "company" then table.insert(fieldmenu, contacts[tablepos].company) end if contactfield == "worktel" then table.insert(fieldmenu, contacts[tablepos].worktel) end if contactfield == "workfax" then table.insert(fieldmenu, contacts[tablepos].workfax) end if contactfield == "workaddr" then table.insert(fieldmenu, contacts[tablepos].workaddr) end if contactfield == "im" then table.insert(fieldmenu, contacts[tablepos].im) end if contactfield == "email" then table.insert(fieldmenu, contacts[tablepos].email) end if contactfield == "mobiletel" then table.insert(fieldmenu, contacts[tablepos].mobiletel) end if contactfield == "webpage" then table.insert(fieldmenu, contacts[tablepos].webpage) end if contactfield == "officeloc" then table.insert(fieldmenu, contacts[tablepos].officeloc) end if contactfield == "hometel" then table.insert(fieldmenu, contacts[tablepos].hometel) end if contactfield == "homeaddr" then table.insert(fieldmenu, contacts[tablepos].homeaddr) end if contactfield == "category" then table.insert(fieldmenu, contacts[tablepos].category) end if contactfield == "otheraddr" then table.insert(fieldmenu, contacts[tablepos].otheraddr) end if contactfield == "pager" then table.insert(fieldmenu, contacts[tablepos].pager) end if contactfield == "cartel" then table.insert(fieldmenu, contacts[tablepos].cartel) end if contactfield == "homefax" then table.insert(fieldmenu, contacts[tablepos].homefax) end if contactfield == "companytel" then table.insert(fieldmenu, contacts[tablepos].companytel) end if contactfield == "work2tel" then table.insert(fieldmenu, contacts[tablepos].work2tel) end if contactfield == "home2tel" then table.insert(fieldmenu, contacts[tablepos].home2tel) end if contactfield == "radiotel" then table.insert(fieldmenu, contacts[tablepos].radiotel) end if contactfield == "im2" then table.insert(fieldmenu, contacts[tablepos].im2) end if contactfield == "im3" then table.insert(fieldmenu, contacts[tablepos].im3) end if contactfield == "email2" then table.insert(fieldmenu, contacts[tablepos].email2) end if contactfield == "manager" then table.insert(fieldmenu, contacts[tablepos].manager) end if contactfield == "assistant" then table.insert(fieldmenu, contacts[tablepos].assistant) end if contactfield == "assistanttel" then table.insert(fieldmenu, contacts[tablepos].assistanttel) end if contactfield == "govtid" then table.insert(fieldmenu, contacts[tablepos].govtid) end if contactfield == "account" then table.insert(fieldmenu, contacts[tablepos].account) end if contactfield == "customerid" then table.insert(fieldmenu, contacts[tablepos].customerid) end if contactfield == "birthday" then table.insert(fieldmenu, contacts[tablepos].birthday) end if contactfield == "anniversary" then table.insert(fieldmenu, contacts[tablepos].anniversary) end if contactfield == "spouse" then table.insert(fieldmenu, contacts[tablepos].spouse) end if contactfield == "children" then table.insert(fieldmenu, contacts[tablepos].children) end if contactfield == "notes" then table.insert(fieldmenu, contacts[tablepos].notes) end -- actually draw the menu s = rb.do_menu("View " .. HumanizeFieldName(contactfield) .. " of " .. contacts[tablepos].first .. " " .. contacts[tablepos].last, fieldmenu, nil, false) if s == -1 or s == 0 or s == -2 then ShowContactScreen(tablepos) -- user selected to go back to the contact view elseif s == -4 or s == 1 then -- edit field of contact rb.splash(rb.HZ, "In development...") elseif s == 2 then -- clear field if contactfield == "first" then contacts[tablepos].first = "" end if contactfield == "middle" then contacts[tablepos].middle = "" end if contactfield == "last" then contacts[tablepos].last = "" end if contactfield == "jobtitle" then contacts[tablepos].jobtitle = "" end if contactfield == "department" then contacts[tablepos].department = "" end if contactfield == "company" then contacts[tablepos].company = "" end if contactfield == "worktel" then contacts[tablepos].worktel = "" end if contactfield == "workfax" then contacts[tablepos].workfax = "" end if contactfield == "workaddr" then contacts[tablepos].workaddr = "" end if contactfield == "im" then contacts[tablepos].im = "" end if contactfield == "email" then contacts[tablepos].email = "" end if contactfield == "mobiletel" then contacts[tablepos].mobiletel = "" end if contactfield == "webpage" then contacts[tablepos].webpage = "" end if contactfield == "officeloc" then contacts[tablepos].officeloc = "" end if contactfield == "hometel" then contacts[tablepos].hometel = "" end if contactfield == "homeaddr" then contacts[tablepos].homeaddr = "" end if contactfield == "category" then contacts[tablepos].category = "" end if contactfield == "otheraddr" then contacts[tablepos].otheraddr = "" end if contactfield == "pager" then contacts[tablepos].pager = "" end if contactfield == "cartel" then contacts[tablepos].cartel = "" end if contactfield == "homefax" then contacts[tablepos].homefax = "" end if contactfield == "companytel" then contacts[tablepos].companytel = "" end if contactfield == "work2tel" then contacts[tablepos].work2tel = "" end if contactfield == "home2tel" then contacts[tablepos].home2tel = "" end if contactfield == "radiotel" then contacts[tablepos].radiotel = "" end if contactfield == "im2" then contacts[tablepos].im2 = "" end if contactfield == "im3" then contacts[tablepos].im3 = "" end if contactfield == "email2" then contacts[tablepos].email2 = "" end if contactfield == "manager" then contacts[tablepos].manager = "" end if contactfield == "assistant" then contacts[tablepos].assistant = "" end if contactfield == "assistanttel" then contacts[tablepos].assistanttel = "" end if contactfield == "govtid" then contacts[tablepos].govtid = "" end if contactfield == "account" then contacts[tablepos].account = "" end if contactfield == "customerid" then contacts[tablepos].customerid = "" end if contactfield == "birthday" then contacts[tablepos].birthday = "" end if contactfield == "anniversary" then contacts[tablepos].anniversary = "" end if contactfield == "spouse" then contacts[tablepos].spouse = "" end if contactfield == "children" then contacts[tablepos].children = "" end if contactfield == "notes" then contacts[tablepos].notes = "" end else end end end load_db() ShowMainMenu()