This just can't be as hard as I'm making it!

I have a list of steps (1-20) each of which has 6 fields attached to it,
e.g.:
smstep1.....smstep20
smstep1title.....smstep20title
smstep1desc....smstep20desc
smstep1prob.....smstep20prob
smstep1note.....smstep20note
smstep1date......smstep20date

Title, desc and prob are stored in table(1), as they apply to a group of
users, while the other 3 reside in table(2), which is particular to a
specfic user.

Now, for the issue: Each group admin can define the actual number of steps
they use, and the order in which they appear, and they can change either at
any time.

I have a field in table(1) called smstepslist which is where I store the
list of steps they choose to use, in their order. (e.g. 3,2,4,1,5,7), and
another where called smsteps where I store the total number of steps they
have in their list. (probably not a necessary duplication)

Here's the problem:
I can't figure out the form to allow them to order the steps. I have to keep
track of the original step number, and then place that number in
"smstepslist" in order, based upon their selection in the select box. (And
delete those where the checkbox is unchecked.) In other words, there are two
lists of step numbers that I have to keep up with...the original, and
theirs.

Below is the 21st iteration, and it still doesn't update correctly! I would
be most grateful for any help on the logic here.

<cfif isDefined("update")>
<cfset newstepslist="#form.formsteps#">
<cfloop from=1 to=#form.smsteps# index=this><cfset fieldname="step#this#">
<cfif listfind("#form.fieldnames#",#this#) is 0><cfset
newstepslist=listdeleteat("#newstepslist#",#this#)></cfif>
</cfloop>

<cfquery datasource=#dsn#>
        update companies set smstepslist = '#newstepslist#' where
companyID=#companyID#
</cfquery>

<cflocation url="preferences.cfm" addtoken=no>

<cfelse>
<cfset find="smsteps, smstepslist">
<cfloop from=1 to=20 index="stepno">
<cfset find=listappend("#find#","SMstep#stepno#title, SMstep#stepno#prob")>
</cfloop>
<cfquery name=get datasource=#dsn#>
        select #find# from companies where companyID = #companyID#
</cfquery>
<br>
<span class=head>Edit Steps</span>
<table cellpadding=3>
        <tr><td colspan=3 class=main>Change the order of your steps by changing the
boxes on the right.<br>
                To eliminate a step, uncheck the box at the left.<br>
                To add steps or edit titles, descriptions or probabilitites, <a
href="stepedit.cfm">CLICK HERE.</a></td>/tr>

<form name=update action="steporder.cfm?update=1" method=post>
<cfoutput>
<input type=hidden name=smsteps value=#get.smsteps#>
<cfset counter=0>
<cfloop list="#get.smstepslist#" index="companystep"><cfset
counter=#counter#+1>
        <cfset title="get.SMstep#companystep#title"><cfset
prob=evaluate("get.SMstep#companystep#prob")*100>
        <tr><td align=right class=bold bgcolor=cccccc>#evaluate(title)#
(#prob#%)</td>
                <td><input type=checkbox name="#companystep#" checked></td>
                <td><select name="formsteps">
                <cfloop from=1 to=#get.smsteps# index=thisno>
                <option value="#thisno#" <cfif #thisno# is
#counter#>selected</cfif>>#thisno#</cfloop></select></td></tr>
</cfloop></cfoutput>
        <tr><td colspan=3 align=center><input type=submit value="update
steps"></td></tr>
</form>
</table>
</cfif>

TIA!!!

*************
Diana Nichols
Webmistress
http://www.lavenderthreads.com

"One man's magic is another man's engineering." ---Lazarus Long


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm

Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to