This example code creates a calendar tabular field using data where each record is an event on a calendar. The data has fields contain the month and year. GROUPSCRIPT is used to call the script for each month group. This data can then be paginated using Master based pagination.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | -- GROUPSCRIPT gets passed a 'recordset' object. -- the 'Month', 'Year' and 'Day' are fields in the data -- Each cell is filled with 'Title' and 'Time' imonth = tonumber(recordset:getrecord(1):field('Month'):content()); iyear = tonumber(recordset:getrecord(1):field('Year'):content()); function get_day_of_week(dd, mm, yy) dw=os.date('*t',os.time{year=yy,month=mm,day=dd})['wday'] return dw,({"Sun","Mon","Tue","Wed","Thu","Fri","Sat" })[dw] end function get_days_in_month(month, year) local days_in_month = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } local d = days_in_month[month] -- check for leap year if (month == 2) then if year % 4 == 0 then if year % 100 == 0 then if year % 400 == 0 then d = 29 end else d = 29 end end end return d end function populate_cell(row, col, day_of_week) for record=1, recordset:size() do myrecord = recordset:getrecord(record); data_day = tonumber(myrecord:getfield('Day'):content()); if data_day == day_of_week then this_entry = "<p>" .. myrecord:getfield('Title'):content() .. "</p>" .. "<p>" .. myrecord:getfield('Time'):content() .. "</p><br/>" table:cell(row,col):setcontent(table:cell(row,col):getcontent() .. this_entry); end end end table = TABLE.new(); table:cell(1,1):setcontent("Sunday"); table:cell(1,2):setcontent("Monday"); table:cell(1,3):setcontent("Tuesday"); table:cell(1,4):setcontent("Wednesday"); table:cell(1,5):setcontent("Thursday"); table:cell(1,6):setcontent("Friday"); table:cell(1,7):setcontent("Saturday"); days_in_month = get_days_in_month(imonth, iyear); first_day_in_month = get_day_of_week(1,imonth,iyear); for day=1,days_in_month do offset = (day-1) + first_day_in_month; row = math.floor((offset-1) / 7) column = math.floor(offset-1) % 7; table:cell((row*2)+2,column+1):setcontent(day); populate_cell((row*2)+3,column+1, day); end; table:present(); |