H DFTACTGRP(*NO) BNDDIR('ERPGSDK') **************************************************************** * External Prototypes * **************************************************************** /COPY QCOPYSRC,P.ERPGSDK /COPY QCOPYSRC,P.STRING /COPY QCOPYSRC,P.G4GCAL /COPY QCOPYSRC,P.LIBL /COPY QCOPYSRC,P.SQL **************************************************************** * Local Prototypes * **************************************************************** D #addEvent... D PR 10i 0 D #deleteEvent... D PR 10i 0 D eventID 256 VALUE **************************************************************** D G4GCDEMODS E DS ExtName(G4GCDEMOPF) Prefix(f_) * * Data Read in from Page D inputDS DS D inAction 10 D inStartDate 10 D inStartTime 8 D inEndDate 10 D inEndTime 8 D inTitle 256 D inLocation 256 D inDescription 4096 D inEventID 256 * D errorMsg S 256 D eventID S 256 D rc S 10i 0 **************************************************************** /free #startup(); #writeTemplate('stdhtmlheader.erpg'); #loadTemplate('message.erpg'); Exsr $Input; Exsr $Process; #cleanup(); *INLR = *on; //**************************************************************** //* Process the Request //**************************************************************** Begsr $Process; select; when (inAction = 'add'); if (#addEvent() >= 0); errorMsg = 'Event added with an ID of ' + %trim(eventID) + ' starting on ' + %trim(inStartDate) + ' at ' + %trim(inStartTime) + ' and ending on ' + %trim(inEndDate) + ' at ' +%trim(inEndTime) + '.'; clear inputDS; endif; when (inAction = 'delete'); if (#deleteEvent(inEventID) >= 0); errorMsg = 'Event ' + %trim(inEventID) + ' deleted.'; clear inputDS; endif; endsl; #replaceData('/%msg%/':errorMsg); #writeSection(); EndSr; //**************************************************************** //* Read input from Web Page //**************************************************************** Begsr $Input; inAction = #getData('action'); inStartDate = #getData('startdate'); inStartTime = #getData('starttime'); inEndDate = #getData('enddate'); inEndTime = #getData('endtime'); inTitle = #getData('title'); inLocation = #getData('location'); inDescription = #getData('description'); inEventID = #getData('eventid'); EndSr; /end-free *//////////////////////////////////////////////////////////////* * #addEvent - Add an event to the calendar * *//////////////////////////////////////////////////////////////* P #addEvent... P B *--------------------------------------------------------------* D #addEvent... D PI 10i 0 * * local variables D l_rc S 10i 0 D l_googleID S 256 D l_calendarID S 256 D l_startDate S D DatFmt(*ISO) D l_startTime S T TimFmt(*HMS) D l_endDate S D DatFmt(*ISO) D l_endTime S T TimFmt(*HMS) *--------------------------------------------------------------* /free test(de) *USA/ inStartDate; if (%error); errorMsg = 'Start Date is Invalid'; return -1; endif; test(te) *HMS: inStartTime; if (%error); errorMsg = 'Start Time is Invalid'; return -1; endif; test(de) *USA/ inEndDate; if (%error); errorMsg = 'End Date is Invalid'; return -1; endif; test(te) *HMS: inEndTime; if (%error); errorMsg = 'End Time is Invalid'; return -1; endif; if (inStartDate > inEndDate); errorMsg = 'Start Date must be <= End Date.'; return -1; endif; if (inStartTime >= inEndTime); errorMsg = 'Start Time must be < End Time.'; return -1; endif; if (inTitle = ' '); errorMsg = 'Title cannot be blank.'; return -1; endif; #pushLib('G4GBVS'); #pushLib('GETURI'); l_googleID = 'bvstone@bvstools.com'; l_calendarID = 'bvstools.com_mq0todpaqahpnpqmmp8u447s40@' + 'group.calendar.google.com'; l_startDate = %date(inStartDate:*USA/); l_startTime = %time(inStartTime:*HMS:); l_endDate = %date(inEndDate:*USA/); l_endTime = %time(inEndTime:*HMS:); l_rc = #g4gcal_setValue('id':l_googleID); l_rc = #g4gcal_setValue('calendar_id':l_calendarID); l_rc = #g4gcal_setValue('event_title':inTitle); l_rc = #g4gcal_setValue('start_date':%char(l_startDate:*USA0)); l_rc = #g4gcal_setValue('start_time':%char(l_startTime:*HMS0)); l_rc = #g4gcal_setValue('end_date':%char(l_endDate:*USA0)); l_rc = #g4gcal_setValue('end_time':%char(l_endTime:*HMS0)); l_rc = #g4gcal_setValue('event_location':inLocation); l_rc = #g4gcal_setValue('event_description':inDescription); l_rc = #g4gcal_addEvent(eventID:errorMsg); #popLib('G4GBVS'); #popLib('GETURI'); if (l_rc >= 0); exec sql insert into G4GCDEMOPF ( ID, CALID, EVTID, TITLE, STARTDATE, STARTTIME, ENDDATE, ENDTIME) VALUES ( :l_googleID, :l_calendarID, :eventID, :inTitle, :l_startDate, :l_startTime, :l_endDate, :l_endTime); else; errorMsg = '#g4gcal_addEvent() Error: ' + %trimr(errorMsg); endif; return l_rc; /end-free *--------------------------------------------------------------* P #addEvent... P E *//////////////////////////////////////////////////////////////* * #deleteEvent - Delete and Event from the calendar * *//////////////////////////////////////////////////////////////* P #deleteEvent... P B *--------------------------------------------------------------* D #deleteEvent... D PI 10i 0 D in_eventID 256 VALUE * * local variables D l_rc S 10i 0 D l_googleID S 256 D l_calendarID S 256 *--------------------------------------------------------------* /free l_googleID = 'bvstone@bvstools.com'; l_calendarID = 'bvstools.com_mq0todpaqahpnpqmmp8u447s40@' + 'group.calendar.google.com'; exec sql select EVTID into :f_EVTID from G4GCDEMOPF where ID = :l_googleID and CALID = :l_calendarID and EVTID = :in_eventID; if (xSQLState2 <> Success_On_Sql); errorMsg = 'Event id ' +%trim(in_eventID) + ' not found.'; return -1; endif; #pushLib('G4GBVS'); #pushLib('GETURI'); l_rc = #g4gcal_setValue('id':l_googleID); l_rc = #g4gcal_setValue('calendar_id':l_calendarID); l_rc = #g4gcal_setValue('event_id':in_eventID); l_rc = #g4gcal_deleteEvent(); #popLib('G4GBVS'); #popLib('GETURI'); if (l_rc >= 0); exec sql delete from G4GCDEMOPF where ID = :l_googleID and CALID = :l_calendarID and EVTID = :in_eventID; endif; return l_rc; /end-free *--------------------------------------------------------------* P #deleteEvent... P E