Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Help with repeating a record based on a date.

Posted on 2002-03-27
13
247 Views
Last Modified: 2013-12-24
Hi all,

I need help making an entry in my CF calendar program repeat.  

What I want to do is offer the customer the option of selecting an option in the add form that would repeat all the fields of the add form for Monday thru Friday of each week of the month.

I will be happy to provide my code so you may interegate, if needed.

Anyone have any ideas on how I can accomplish this?
0
Comment
Question by:g118481
  • 6
  • 6
13 Comments
 
LVL 19

Expert Comment

by:cheekycj
ID: 6899850
like if repeat is checked.. then loop through M-F and add it to your calendar DB?

CJ
0
 
LVL 1

Author Comment

by:g118481
ID: 6899869
Yes.
I think the difficulty of this task is how to calculate the new date for each new record.

Now, I know I want the form fields to be exactly the same, however, I really don't know how to repricate each new record with the next date in the week.

Maybe it would be better if my new code would just repricate the remainder of the current week only.
(my reference to week applies to Monday - Friday only)
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 6899895
Do you want it to repeat continuously (over next x weeks) or JUST the current week.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 1

Author Comment

by:g118481
ID: 6899934
Would it be difficult for the code to repeat the selected event for one month at a time?

If not, then I would like that, else it shouldn't repeat for more than a single year at a time so the db doesn't grow too large at one time.  Also, there has to be some kind of limit, less the code goes into an infinite loop, right?

Thanks
0
 
LVL 1

Author Comment

by:g118481
ID: 6902530
Cheekycj,

any help you offer would be very much appreciated.
0
 
LVL 3

Expert Comment

by:winningl
ID: 6902694

Can you post some of your code?

I'm not sure what you want. Do you mean to loop through M to F and add the same form data into DB? What's the primary key in your table?

winningl
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 6902785
winning! I think that is exactly what he wants.

sorta like:

<!--- Assuming VARIABLES.startDate is the start Date --->
<!--- init loop start for first week --->
<cfif DayOfWeek(VARIABLES.startDate) EQ 1>
     <cfset VARIABLES.startDate = DateAdd("d", 1, VARIABLES.startDate)>
<cfelseif DayOfWeek(VARIABLES.startDate) EQ 7>
     <cfset VARIABLES.startDate = DateAdd("d", 2, VARIABLES.startDate)>
</cfif>
<cfset VARIABLES.loopStart = DayOfWeek(VARIABLES.startDate)>
<cfloop index="i" from="#VARIABLES.loopStart#" to="6" step="1">
     <!--- Put query here to insert into DB using VARIABLES.startDate as the time --->
     <cfset VARIABLES.startDate = DateAdd("d", 1, VARIABLES.startDate)>
</cfloop>
<!--- Add 2 days to adjust for weekend --->
<cfset VARIABLES.startDate = DateAdd("d", 2, VARIABLES.startDate)>
<!--- Now add 4 more weeks -- 1 month --->
<cfloop index="w" from="1" to="4" step="1">
     <cfloop index="d" from="2" to="6" step="1">
          <!--- Put query here to insert into DB using VARIABLES.startDate as the time --->
          <cfset VARIABLES.startDate = DateAdd("d", 1, VARIABLES.startDate)>
     </cfloop>
     <!--- Add 2 days for weekend --->
     <cfset VARIABLES.startDate = DateAdd("d", 2, VARIABLES.startDate)>
</cfloop>
0
 
LVL 1

Author Comment

by:g118481
ID: 6903216
Thanks for the update.

How would I implement your suggested code into my add/edit form listed below.

/**************************************************/
<CFSET FIELDLIST = "FuseCalendar_ID,CalendarDate,EventDescription,Location,Email,Website,EventName,Contact,Phone,ShowTime,FuseBox_ID">


<CFIF attributes.fuseaction IS "AddEvent">
      <!--- If adding a new event, this code is run, setting each form field to empty.      --->
      <CFLOOP LIST="#fieldlist#" INDEX="counter">
            <CFSET TEMP = SETVARIABLE("#counter#", "")>
      </CFLOOP>
      <cfset time = "8:00 AM">
<CFELSEIF attributes.fuseaction IS "EditEventID">
      <!--- if the user is creating a editing a record --->
      <CFQUERY NAME="getEvent" DATASOURCE="cmrmm">
            select *
                  from event
                        where FuseCalendar_ID = #attributes.FuseCalendar_ID#
      </CFQUERY>
      
      <!--- I will now set the form field variables to the event to be edited based on the record taken from the query above.      --->
      <CFLOOP LIST="#fieldlist#" INDEX="counter">
            <CFSET TEMP = SETVARIABLE("#counter#", "#evaluate("GetEvent." & "#COUNTER#")#")>
      </CFLOOP>
      <cfset Time = "#TimeFormat(CalendarDate)#">
      
<CFELSEIF attributes.fuseaction IS "RemoveEventID">
      <!--- This code is similar to the editing of an event, but will just display the data that is about to be deleted. --->
      <CFQUERY NAME="getEvent" DATASOURCE="cmrmm">
            select *
            from event
            where FuseCalendar_ID = #attributes.FuseCalendar_ID#
      </CFQUERY>
      
      <CFLOOP LIST="#fieldlist#" INDEX="counter">
            <CFSET TEMP = SETVARIABLE("#counter#", "#evaluate("GetEvent." & "#COUNTER#")#")>
      </CFLOOP>
      
      <cfset Time = "#TimeFormat(CalendarDate)#">
</CFIF>
<blockquote></blockquote>
<html>
<head>
      <title>Alter the Event Data for the Calendar.</title>
</head>

<Body background="/release/bg_stripe.gif" rightmargin="2" leftmargin="2">

You are about to <cfif attributes.fuseaction is "AddEvent"><B>add</B> a new event to<cfelseif attributes.fuseaction is "EditEventID"><B>modify</B> an event on<cfelseif attributes.fuseaction is "RemoveEventID">remove an event on</CFIF> the Calendar.  Fill out the form below.  All fields in <FONT COLOR="#800000">red</FONT> are required.<p>

<FORM ACTION="index.cfm" METHOD="post">
      <INPUT Type="Hidden" Name="fuseaction" Value="<cfoutput>#attributes.fuseaction#Process</cfoutput>">
      
      <INPUT TYPE="HIDDEN" NAME="FuseCalendar_ID" value="<CFOUTPUT>#FuseCalendar_ID#</CFOUTPUT>">
      <TABLE border="0">

  <TR>
                <TD VALIGN="top"><FONT COLOR="800000">Event Name:</FONT> </TD>
                <TD>
                        <INPUT TYPE="text" NAME="EventName" SIZE="20" MaxSize="100"<CFOUTPUT>value="#EventName#"</CFOUTPUT>>
                  </TD>
            </TR>
            
            <TR>
                <TD VALIGN="top"><FONT COLOR="800000"></FONT> </TD>

 <TR>
                <TD VALIGN="top"><FONT COLOR="#800000">Location:</FONT> </TD>
                <TD>
                         <INPUT TYPE="text" NAME="Location" SIZE="20" MaxSize="100"<CFOUTPUT>value="#Location#"</CFOUTPUT>
                  </TD>
            </TR>

            <TR>
                <TD VALIGN="top"><FONT COLOR="800000">Date:</FONT> </TD>
                <TD>
                        <INPUT TYPE="text" NAME="CalendarDate" SIZE="20" MaxSize="100"<CFOUTPUT>value="<cfif CalendarDate NEQ "">#DateFormat(CalendarDate)#<cfelse>#DateFormat(NOW())#</CFIF>"</CFOUTPUT>>
                        <input type="hidden" Name="CalendarDate_Date" Value="The Date must be in a valid format, such as 4/27/1998">
                  </TD>
            </TR>

            

             <TR>
                <TD VALIGN="top">Time:</TD>
                <TD>
                        Show? Yes <INPUT TYPE="Radio" NAME="ShowTime" VALUE="YES" <cfif ShowTime is "YES">CHECKED</CFIF>>
                        No <INPUT TYPE="Radio" NAME="ShowTime" VALUE="NO" <cfif ShowTime NEQ "YES">CHECKED</CFIF>> Time:
                        <INPUT TYPE="text" NAME="Time" SIZE="20" MaxSize="100"<CFOUTPUT>value="#Time#"</CFOUTPUT>>
                  </TD>
            </TR>
                  
             <TR>
                <TD VALIGN="top">Contact Name:</TD>
                <TD>
                        <INPUT TYPE="text" NAME="Contact" SIZE="20" MaxSize="50"<CFOUTPUT>value="#Contact#"</CFOUTPUT>>
                  </TD>
            </TR>

             <TR>
                <TD VALIGN="top">Phone Number:</TD>
                <TD>
                        <INPUT TYPE="text" NAME="phone" SIZE="20" MaxSize="50"<CFOUTPUT>value="#phone#"</CFOUTPUT>>
                  </TD>
            </TR>

             <TR>
                <TD VALIGN="top">Email:</TD>
                <TD>
                        <INPUT TYPE="text" NAME="Email" SIZE="20" MaxSize="50"<CFOUTPUT>value="#Email#"</CFOUTPUT>>
                  </TD>
            </TR>

             <TR>
                <TD VALIGN="top">Web Site Address:</TD>
                <TD>
                        http://<INPUT TYPE="text" NAME="WebSite" SIZE="20" MaxSize="50"<CFOUTPUT>value="#WebSite#"</CFOUTPUT>>
                  </TD>
            </TR>

             <TR>
                <TD VALIGN="top"><FONT COLOR="800000">Event Description:</FONT> </TD>
                <TD>
                        <TextArea NAME="EventDescription" Cols="45" ROWS="7" Wrap=Virtual><CFOUTPUT>#EventDescription#</CFOUTPUT></textarea>
                  </TD>
            </TR>
                              
      <tr>
            <td></TD>
            <td>
                  <input type="hidden" name="FuseBox_ID" Value="999">
                  <input type="hidden" name="EventDescription_required" Value="You must provide a description for your event.">
                  <input type="hidden" name="EventName_required" Value="You must provide a name for your event.">      
                  <!--- <input type="hidden" name="Location_required" Value="You must provide a location for your event."> --->
                  <input type="hidden" name="CalendarDate_required" Value="You must provide a description for your event.">
                  <INPUT TYPE="submit" VALUE="Make It Happen">
            </TD>
      </TR>

</FORM>
      </TABLE>
</body>
</html>
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 6903229
that is your form page right.. what about the page that actually inserts the info into the DB?
0
 
LVL 1

Author Comment

by:g118481
ID: 6903475
Sorry,

I should have included my action page.  Here it is.
Thanks for your time!

/****************************************************/
<cftransaction>
     <cfmodule template="act_max_id.cfm"
          datasource="cmrmm"
          tablename="event"
          primarykey="FuseCalendar_id">
               
     <cfquery name="addToCalendar" datasource="cmrmm">
          Insert Into Event
          (FuseCalendar_ID, FuseBox_ID, CalendarDate, EventDescription, location, email, Website, EventName, contact, phone, showtime)
               Values (#max_id#, #attributes.fusebox_id#, #ParseDateTime("#dateformat(attributes.CalendarDate)# #TimeFormat(attributes.Time)#")#, '#ParagraphFormat(attributes.EventDescription)#', '#attributes.location#',  '#attributes.email#', '#attributes.website#', '#attributes.eventname#', '#attributes.contact#', '#attributes.phone#', #attributes.showtime#)
     </CFQUERY>
</cftransaction>
0
 
LVL 19

Accepted Solution

by:
cheekycj earned 100 total points
ID: 6903530
is attributes.CalendarDate the startDate?

then it would be:

<!--- Assuming VARIABLES.startDate is the start Date --->
<cfset VARIABLES.startDate = attributes.CalendarDate>
<!--- init loop start for first week --->
<cfif DayOfWeek(VARIABLES.startDate) EQ 1>
    <cfset VARIABLES.startDate = DateAdd("d", 1, VARIABLES.startDate)>
<cfelseif DayOfWeek(VARIABLES.startDate) EQ 7>
    <cfset VARIABLES.startDate = DateAdd("d", 2, VARIABLES.startDate)>
</cfif>
<cfset VARIABLES.loopStart = DayOfWeek(VARIABLES.startDate)>
<cfloop index="i" from="#VARIABLES.loopStart#" to="6" step="1">
    <cfquery name="addToCalendar" datasource="cmrmm">
         Insert Into Event
         (FuseCalendar_ID, FuseBox_ID, CalendarDate, EventDescription, location, email, Website, EventName,
contact, phone, showtime)
              Values (#max_id#, #attributes.fusebox_id#, #ParseDateTime("#dateformat(VARIABLES.startDate)#
#TimeFormat(attributes.Time)#")#, '#ParagraphFormat(attributes.EventDescription)#', '#attributes.location#',
 '#attributes.email#', '#attributes.website#', '#attributes.eventname#', '#attributes.contact#', '#attributes.phone#',
#attributes.showtime#)
    </CFQUERY>
    <cfset VARIABLES.startDate = DateAdd("d", 1, VARIABLES.startDate)>
</cfloop>
<!--- Add 2 days to adjust for weekend --->
<cfset VARIABLES.startDate = DateAdd("d", 2, VARIABLES.startDate)>
<!--- Now add 4 more weeks -- 1 month --->
<cfloop index="w" from="1" to="4" step="1">
    <cfloop index="d" from="2" to="6" step="1">
    <cfquery name="addToCalendar" datasource="cmrmm">
         Insert Into Event
         (FuseCalendar_ID, FuseBox_ID, CalendarDate, EventDescription, location, email, Website, EventName,
contact, phone, showtime)
              Values (#max_id#, #attributes.fusebox_id#, #ParseDateTime("#dateformat(VARIABLES.startDate)#
#TimeFormat(attributes.Time)#")#, '#ParagraphFormat(attributes.EventDescription)#', '#attributes.location#',
 '#attributes.email#', '#attributes.website#', '#attributes.eventname#', '#attributes.contact#', '#attributes.phone#',
#attributes.showtime#)
    </CFQUERY>
         <cfset VARIABLES.startDate = DateAdd("d", 1, VARIABLES.startDate)>
    </cfloop>
    <!--- Add 2 days for weekend --->
    <cfset VARIABLES.startDate = DateAdd("d", 2, VARIABLES.startDate)>
</cfloop>
0
 
LVL 1

Author Comment

by:g118481
ID: 6910309
Cheekycj,

I have tested your code, and I am not getting the results I expected.

It is writing 25 records for April (the current month now), and all are exact duplicated of eachother, including the "startdate"

How can I change the code to add the next number of the day to the startdate field?

Thanks.
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 6918636
you used the above code exactly??

I am incrementing startDate which is what gets inserted.. you have to use the queries I have not the ones you have which use attributes.CalendarDate or replace it with VARIABLES.startDate.

CJ
0

Featured Post

Connect further...control easier

With the ATEN CE624, you can now enjoy a high-quality visual experience powered by HDBaseT technology and the convenience of a single Cat6 cable to transmit uncompressed video with zero latency and multi-streaming for dual-view applications where remote access is required.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question