Advertisement
aparker81

Score Poem

May 31st, 2011
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <cfsilent>
  2.  
  3.     <cfquery name="qGetPoem"  datasource="#request.dsn#">
  4.         SELECT poemID, poemTitle, poemContent
  5.         FROM  PoetryContest
  6.         WHERE poemID = <cfqueryparam cfsqltype="cf_sql_varchar" value="#url.id#">
  7.     </cfquery>
  8.  
  9.     <!--- Define an array to catch the form errors. --->
  10.     <cfset arrDuplicate = ArrayNew( 1 ) />
  11.  
  12.         <cfquery name="duplicateCheck" datasource="#request.dsn#">
  13.             SELECT score, judgeID
  14.             FROM PoemScores
  15.             WHERE judgeID = '#session.username#' and poemID = #url.id#
  16.         </cfquery>
  17.    
  18.         <cfif duplicateCheck.recordCount GT '0'>
  19.             <cfset ArrayAppend(
  20.                 arrDuplicate,
  21.                 "You have previously scored this poem.  Submitting your score will overwrite your previous score."
  22.                 ) />
  23.         </cfif>
  24.    
  25.     <cfset newLine = Chr(13) & Chr(10)>
  26.    
  27.     <!--- Param FORM variables. --->
  28.  
  29.     <cfparam
  30.         name="FORM.rating"
  31.         type="string"
  32.         default=""
  33.         />
  34.  
  35.     <!---
  36.         For the form submission flag, since we are asking
  37.         it to be of type numeric, we have to catch the
  38.         CFParam in case someone has hacked the HTML and
  39.         altered the value being sent (a non-numeric value
  40.         will throw a ColdFusion error).
  41.     --->
  42.     <cftry>
  43.         <cfparam
  44.             name="FORM.submitted"
  45.             type="numeric"
  46.             default="0"
  47.             />
  48.  
  49.         <!--- Catch CFParam data type errors. --->
  50.         <cfcatch>
  51.             <cfset FORM.submitted = 0 />
  52.         </cfcatch>
  53.     </cftry>
  54.  
  55.  
  56.     <!--- Define an array to catch the form errors. --->
  57.     <cfset arrErrors = ArrayNew( 1 ) />
  58.  
  59.  
  60.     <!--- Check to see if the form has been submitted. --->
  61.     <cfif FORM.submitted>
  62.  
  63.         <!---
  64.             Now that the form has been submitted, we need
  65.             to validate the data.
  66.         --->
  67.        
  68.  
  69.         <!--- Validate first name. --->
  70.         <cfif NOT Len( FORM.rating )>
  71.             <cfset ArrayAppend(
  72.                 arrErrors,
  73.                 "You must rate the poem."
  74.                 ) />
  75.         </cfif>
  76.  
  77.  
  78.         <!---
  79.             Now that we have validated our form data, let's
  80.             check to see if there are any form validation
  81.             errors. Only if there are no errors do w want to
  82.             continue processing the data - otherwise, we want
  83.             to skip this next part and let the form re-render.
  84.         --->
  85.        
  86.         <cfif NOT ArrayLen( arrErrors ) >
  87.             <cfquery name="updateScore" datasource="#request.dsn#">
  88.                 UPDATE PoemScores
  89.                 SET score = '#form.rating#'
  90.  
  91.                 WHERE poemID = <cfqueryparam cfsqltype="cf_sql_varchar" value="#url.id#">
  92.             </cfquery>
  93.         </cfif>
  94.        
  95.         <cfif NOT ArrayLen( arrErrors )>
  96.  
  97.             <!--- INSERT DATABASE QUERY--->
  98.             <cfquery name="qRatePoem" datasource="#request.dsn#">
  99.                 INSERT INTO PoemScores (poemID, score, judgeID)
  100.                 VALUES ('#url.id#', '#form.rating#', '#session.username#')
  101.             </cfquery>
  102.        
  103.            
  104.    
  105.             <!---<cflocation url="dash.cfm" addtoken="no">--->
  106.                
  107.         </cfif>
  108.  
  109.     </cfif>
  110.  
  111.  
  112. </cfsilent>
  113.  
  114. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  115. <html xmlns="http://www.w3.org/1999/xhtml">
  116. <head>
  117. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  118. <title>Poem Overview</title>
  119. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
  120.  
  121. <style>
  122.     body {font-family: "Helvetica Neue", Helvetica, Arial, Sans-serif; font-size: 0.875em; line-height: 1.3}
  123.     #poem {width:450px; position:relative;margin-left:auto; margin-right:auto; top: 90px;}
  124.     #poem h3{font-size:20px;font-weight:normal;background:#b9c9fe;border-top:4px solid #aabcfe;color:#039;padding:8px;margin-bottom:0;}
  125.     #poem p{background:#e8edff;border-bottom:1px solid #fff;color:#669;border-top:1px solid transparent;padding:0 7px 7px 7px; margin:0;}
  126.     .rating{ }
  127. </style>
  128.  
  129. </head>
  130.  
  131. <body>
  132.     <div id="content">
  133.    
  134.         <div id="poem">
  135.             <cfoutput query="qGetPoem">
  136.             <cfif ArrayLen( arrErrors )>
  137.                     <h2>Please review the following:</h2>
  138.          
  139.                     <ul>
  140.                         <cfloop
  141.                             index="intError"
  142.                             from="1"
  143.                             to="#ArrayLen( arrErrors )#"
  144.                             step="1">
  145.          
  146.                             <li>
  147.                                 #arrErrors[ intError ]#
  148.                             </li>
  149.          
  150.                         </cfloop>
  151.                     </ul>
  152.                
  153.                 </cfif>
  154.                
  155.                 <cfif ArrayLen( arrDuplicate)>
  156.                     <h2>Attention:</h2>
  157.          
  158.                     <ul>
  159.                         <cfloop
  160.                             index="intError"
  161.                             from="1"
  162.                             to="#ArrayLen( arrDuplicate )#"
  163.                             step="1">
  164.          
  165.                             <li>
  166.                                 #arrDuplicate[ intError ]#
  167.                             </li>
  168.          
  169.                         </cfloop>
  170.                     </ul>
  171.                
  172.                 </cfif>
  173.                
  174.                
  175.                 <h3>#poemTitle#</h3>
  176.                     <div class="rating">
  177.                         <form
  178.                             action="#cgi.SCRIPT_NAME#?id=#url.id#"
  179.                             method="post"
  180.                             enctype="multipart/form-data">
  181.                                 <!--- Our form submission flag. --->
  182.                                 <input type="hidden" name="submitted" value="1" />
  183.                                 <input type="hidden" value="#id#" />
  184.                                         <select name="rating">
  185.                                            
  186.                                                 <option value="">&ndash; Rate This Poem &ndash;</option>
  187.                                                 <option value="1"<cfif duplicateCheck.score eq 1> selected="selected"</cfif>>1</option>
  188.                                                 <option value="2"<cfif duplicateCheck.score eq 2> selected="selected"</cfif>>2</option>
  189.                                                 <option value="3"<cfif duplicateCheck.score eq 3> selected="selected"</cfif>>3</option>
  190.  
  191.                                            
  192.  
  193.                                         </select>
  194.                                 <input type="submit" value="Rate It!" />
  195.                         </form>
  196.                     </span>    
  197.                
  198.            
  199.                 <p>#Replace(poemContent, newLine, "<br>", "ALL")#</p>
  200.  
  201.             </cfoutput>
  202.         </div>
  203.   </div>
  204. </div>
  205. </body>
  206. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement