Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
titleexecute.cfm
<cfsetting enablecfoutputonly="true" />
<!--- @@displayname: Execute Poll --->
<!--- @@description:  --->

<cfimport taglib="/farcry/core/tags/formtools" prefix="ft" />
<cfimport taglib="/farcry/core/tags/webskin" prefix="skin" />

<cfset pollid = replace(stObj.objectid,'-','','ALL') />

<cfparam name="url.showresult" default="" />


<!--- Process poll --->
<ft:processform action="#stObj.submitlabel#">
	<cfif structkeyexists(form,pollid)>
		<cfset stObj["result#form[pollid]#"] = stObj["result#form[pollid]#"]+1 />
		<!--- 
		set user to anonymous; 
		otherwise setData() will try and pick up the active session requiring users to login 
		--->
		<cfset setData(stProperties=stObj,user="anonymous") />
		
		<cfparam name="session.polls" default="#structnew()#" />
		<cfset session.polls[pollid] = true />
	</cfif>
</ft:processform>

<ft:processform action="View Results #pollid#">
	<cfset url.showresult = pollid />
</ft:processform>


<!--- View poll --->
<cfif url.showresult eq pollid or structkeyexists(session,"polls") and structkeyexists(session.polls,pollid) and session.polls[pollid]>
	<!--- User has already answered the poll, show results --->
	
	<!--- Calculate total --->
	<cfset total = 0 />
	<cfloop from="1" to="6" index="i">
		<cfset total = total + stObj["result#i#"] />
	</cfloop>
	
	<cfoutput>
		<div class="poll">
			<p class="pollquestion">#stObj.question#</p>
	</cfoutput>
	
	<cfloop from="1" to="6" index="i">
		<cfif len(trim(stObj["answer#i#"]))>
			<cfoutput>
				<table class="pollresult">
					<tr>
						<td class="pollanswer" colspan="2">#stObj["answer#i#"]#</td>
					</tr>
					<tr>
						<td class="resultbar" width="#round(stObj['result#i#']/total*70)#%"></td>
						<td class="resultlabel">#round(stObj['result#i#']/total*100)#%</td>
					</tr>
				</table>
			</cfoutput>
		</cfif>
	</cfloop>
	
	<cfif url.showresult eq pollid>
		<skin:buildLink objectid="#request.stObj.objectid#"><cfoutput>Return to Poll</cfoutput></skin:buildLink>
	</cfif>
	
	<cfoutput>
		</div>
	</cfoutput>
<cfelse>
	<!--- User has not answered the poll, show the poll form --->
	
	<ft:form>
		<cfoutput>
			<div class="poll">
				<p class="pollquestion">#stObj.question#</p>
				<table class="pollanswers">
		</cfoutput>
		
		<cfloop from="1" to="6" index="i">
			
			<cfif len(trim(stObj["answer#i#"]))>
				<cfoutput>
					<tr class="pollanswer">
						<td class="answerradio" valign="top"><input class="answerinput" type="radio" value="#i#" name="#pollid#" value="#i#" id="#pollid#_#i#" /></td>
						<td class="answerlabel"><label class="answerlabel" for="#pollid#_#i#">#stObj["answer#i#"]#</label></td>
					</tr>
				</cfoutput>
			</cfif>
		</cfloop>
		
		<cfoutput>
				</table>
		</cfoutput>
		
		<skin:buildLink objectid="#request.stObj.objectid#" urlParameters="showresult=#pollid#"><cfoutput>View Results</cfoutput></skin:buildLink>
		<ft:button value="#stObj.submitlabel#" size="small" />
		
		<cfoutput>
			</div>
		</cfoutput>
	</ft:form>
</cfif>


<cfsetting enablecfoutputonly="false" />

...