Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Help with repeating a record based on a date.

Posted on 2002-03-27
13
Medium Priority
?
252 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
[X]
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
  • 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
Looking for a new Web Host?

Lunarpages' assortment of hosting products and solutions ensure a perfect fit for anyone looking to get their vision or products to market. Our award winning customer support and 30-day money back guarantee show the pride we take in being the industry's premier MSP.

 
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 300 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

Simplify Your Workload with One Tool

How do you combat today’s intelligent hacker while managing multiple domains and platforms? By simplifying your workload with one tool. With Lunarpages hosting through Plesk Onyx, you can:

Automate SSL generation and installation with two clicks
Experience total server control

Question has a verified solution.

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

Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

604 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