| 1 | <cfsetting enablecfoutputonly=true showdebugoutput=false> |
|---|
| 2 | <!--- |
|---|
| 3 | Name : stats.cfm |
|---|
| 4 | Author : Raymond Camden |
|---|
| 5 | Created : September 6, 2004 |
|---|
| 6 | Last Updated : March 30, 2006 |
|---|
| 7 | History : For some dumb reason, Excel output was commented out (rkc 8/26/05) |
|---|
| 8 | Support matrix (rkc 10/8/05) |
|---|
| 9 | Forgot some debug output (rkc 10/28/05) |
|---|
| 10 | Fixed ordering in matrix questions (rkc 2/11/06) |
|---|
| 11 | Fixed CFMX6 support (rkc 3/22/06) |
|---|
| 12 | tableprefix fix (rkc 3/30/06) |
|---|
| 13 | Purpose : |
|---|
| 14 | ---> |
|---|
| 15 | <cfimport taglib="../tags/" prefix="tags"> |
|---|
| 16 | |
|---|
| 17 | <!--- Is this a mx7 box? ---> |
|---|
| 18 | <cfif structKeyExists(getFunctionList(), "GetLocaleDisplayName")> |
|---|
| 19 | <cfset cfmx7 = true> |
|---|
| 20 | <cfelse> |
|---|
| 21 | <cfset cfmx7 = false> |
|---|
| 22 | </cfif> |
|---|
| 23 | |
|---|
| 24 | <cfif isDefined("url.surveyidfk")> |
|---|
| 25 | <cfset form.surveyidfk = url.surveyidfk> |
|---|
| 26 | </cfif> |
|---|
| 27 | <cfparam name="form.surveyidfk" default=""> |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | <cfif form.surveyidfk is ""> |
|---|
| 31 | |
|---|
| 32 | <tags:layout templatename="admin" title="Stats" loadspry="true"> |
|---|
| 33 | |
|---|
| 34 | <!--- get surveys ---> |
|---|
| 35 | <cfset surveys = application.survey.getSurveys()> |
|---|
| 36 | |
|---|
| 37 | <cfoutput> |
|---|
| 38 | <script> |
|---|
| 39 | var dsQuestions = new Spry.Data.XMLDataSet("", "/questions/question"); |
|---|
| 40 | |
|---|
| 41 | function getQuestions() { |
|---|
| 42 | var selq = Spry.$("selquestions"); |
|---|
| 43 | if(!selq.checked) { |
|---|
| 44 | clearQuestions(); |
|---|
| 45 | return; |
|---|
| 46 | } |
|---|
| 47 | surveydd = Spry.$("surveyidfk"); |
|---|
| 48 | survey = surveydd.options[surveydd.selectedIndex].value; |
|---|
| 49 | dsQuestions.setURL("xml.questions.cfm?survey="+survey); |
|---|
| 50 | dsQuestions.loadData(); |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | function clearQuestions() { |
|---|
| 54 | var q = Spry.$("questionlist"); |
|---|
| 55 | q.innerHTML = ''; |
|---|
| 56 | } |
|---|
| 57 | </script> |
|---|
| 58 | <p> |
|---|
| 59 | <form action="#cgi.script_name#" method="post" name="surveys"> |
|---|
| 60 | Select a Survey <select name="surveyidfk" id="surveyidfk"> |
|---|
| 61 | <cfloop query="surveys"> |
|---|
| 62 | <option value="#id#" <cfif id is form.surveyidfk>selected</cfif>>#name#</option> |
|---|
| 63 | </cfloop> |
|---|
| 64 | </select> |
|---|
| 65 | <select name="format"> |
|---|
| 66 | <option value="html">HTML</option> |
|---|
| 67 | <option value="excel">Excel</option> |
|---|
| 68 | <option value="pdf">PDF</option> |
|---|
| 69 | </select> |
|---|
| 70 | <input type="submit" value="Generate"><br /> |
|---|
| 71 | <input type="checkbox" id="selquestions" value="selectquestions" onclick="getQuestions()">Select Questions: |
|---|
| 72 | <div id="questionlist" spry:region="dsQuestions"> |
|---|
| 73 | <ul> |
|---|
| 74 | <div spry:repeat="dsQuestions"> |
|---|
| 75 | <input type="checkbox" name="questionfilter" value="{ID}"><span spry:content="{QUESTION}"></span><br /> |
|---|
| 76 | </div> |
|---|
| 77 | </ul> |
|---|
| 78 | </div> |
|---|
| 79 | </form> |
|---|
| 80 | </p> |
|---|
| 81 | </cfoutput> |
|---|
| 82 | |
|---|
| 83 | </tags:layout> |
|---|
| 84 | |
|---|
| 85 | <!--- begin report handling ---> |
|---|
| 86 | <cfelse> |
|---|
| 87 | |
|---|
| 88 | <!--- handle questions and possible filter ---> |
|---|
| 89 | <cfset questions = application.question.getQuestions(form.surveyidfk)> |
|---|
| 90 | |
|---|
| 91 | <cfif structKeyExists(form, "questionfilter") and len(form.questionfilter)> |
|---|
| 92 | <cfquery name="questions" dbtype="query"> |
|---|
| 93 | select * |
|---|
| 94 | from questions |
|---|
| 95 | where id in (<cfqueryparam cfsqltype="cf_sql_varchar" value="#form.questionfilter#" list="true">) |
|---|
| 96 | </cfquery> |
|---|
| 97 | </cfif> |
|---|
| 98 | |
|---|
| 99 | |
|---|
| 100 | |
|---|
| 101 | <!--- html ---> |
|---|
| 102 | <cfif form.format is "html"> |
|---|
| 103 | |
|---|
| 104 | <!--- Begin Stat Display ---> |
|---|
| 105 | <cfset survey = application.survey.getSurvey(form.surveyidfk)> |
|---|
| 106 | <cfset stats = application.survey.getStats(form.surveyidfk)> |
|---|
| 107 | |
|---|
| 108 | <tags:layout templatename="admin" title="Stats for #survey.name#"> |
|---|
| 109 | |
|---|
| 110 | <cfoutput> |
|---|
| 111 | |
|---|
| 112 | <script> |
|---|
| 113 | function popup(loc) { |
|---|
| 114 | theWin = window.open(loc,'theWin','width=600,height=600'); |
|---|
| 115 | theWin.focus(); |
|---|
| 116 | } |
|---|
| 117 | </script> |
|---|
| 118 | |
|---|
| 119 | <p> |
|---|
| 120 | <table cellspacing=0 cellpadding=5 class="adminListTable" width="600"> |
|---|
| 121 | <tr class="adminListHeader"> |
|---|
| 122 | <td colspan="2">General Stats</td> |
|---|
| 123 | </tr> |
|---|
| 124 | <tr> |
|---|
| 125 | <td><b>Total Number of Survey Results</b></td> |
|---|
| 126 | <td>#stats.totalresults#</td> |
|---|
| 127 | </tr> |
|---|
| 128 | <tr> |
|---|
| 129 | <td><b>First Result</b></td> |
|---|
| 130 | <td>#dateFormat(stats.firstresult,"m/dd/yy")# #timeFormat(stats.firstresult,"h:mm tt")# </td> |
|---|
| 131 | </tr> |
|---|
| 132 | <tr> |
|---|
| 133 | <td><b>Last Result</b></td> |
|---|
| 134 | <td>#dateFormat(stats.lastresult,"m/dd/yy")# #timeFormat(stats.lastresult,"h:mm tt")# </td> |
|---|
| 135 | </tr> |
|---|
| 136 | <tr> |
|---|
| 137 | <td colspan="2"> |
|---|
| 138 | <a href="#cgi.script_name#?surveyidfk=#form.surveyidfk#&excel=true">Excel Report</a> |
|---|
| 139 | </td> |
|---|
| 140 | </tr> |
|---|
| 141 | </table> |
|---|
| 142 | </p> |
|---|
| 143 | </cfoutput> |
|---|
| 144 | |
|---|
| 145 | <cfset colorList = "##E48701,##A5BC4E,##1B95D9,##CACA9E,##6693B0,##F05E27,##86D1E4,##E4F9A0,##FFD512,##75B000,##0662B0"> |
|---|
| 146 | <cfset currentColorIndex = 1> |
|---|
| 147 | |
|---|
| 148 | <cfloop query="questions"> |
|---|
| 149 | |
|---|
| 150 | <!--- fire stats handler for qt ---> |
|---|
| 151 | <cfmodule template="../handlers/#handlerRoot#/stats.cfm" |
|---|
| 152 | surveyidfk="#form.surveyidfk#" |
|---|
| 153 | questionidfk="#id#" |
|---|
| 154 | r_data="data" |
|---|
| 155 | /> |
|---|
| 156 | |
|---|
| 157 | <cfif isStruct(data) and questiontype is not "matrix"> |
|---|
| 158 | <!--- get max data ---> |
|---|
| 159 | <cfset max = 1> |
|---|
| 160 | <cfloop item="key" collection="#data#"> |
|---|
| 161 | <cfif data[key] gt max> |
|---|
| 162 | <cfset max = data[key]> |
|---|
| 163 | </cfif> |
|---|
| 164 | </cfloop> |
|---|
| 165 | </cfif> |
|---|
| 166 | |
|---|
| 167 | <cfset currentColor = listGetAt(colorList, currentColorIndex)> |
|---|
| 168 | <cfoutput> |
|---|
| 169 | <p> |
|---|
| 170 | <table cellspacing=0 cellpadding=5 class="adminListTable" width="600"> |
|---|
| 171 | <tr class="adminListHeader"> |
|---|
| 172 | <td colspan="2">#rank#. #question# (#questiontype#)</td> |
|---|
| 173 | </tr> |
|---|
| 174 | <tr> |
|---|
| 175 | <td> |
|---|
| 176 | <cfswitch expression="#questiontype#"> |
|---|
| 177 | |
|---|
| 178 | <cfcase value="true/false,yes/no"> |
|---|
| 179 | <cfif questiontype is "true/false"> |
|---|
| 180 | <cfset t = "True"> |
|---|
| 181 | <cfset f = "False"> |
|---|
| 182 | <cfelse> |
|---|
| 183 | <cfset t = "Yes"> |
|---|
| 184 | <cfset f = "No"> |
|---|
| 185 | </cfif> |
|---|
| 186 | <cfchart format="flash" chartWidth="575" chartHeight="575" |
|---|
| 187 | rotated="yes" gridLines="#max+1#"> |
|---|
| 188 | <cfchartseries type="bar" paintStyle="raise" seriesColor="#currentColor#"> |
|---|
| 189 | <cfchartdata item="#f#" value="#data.false#"> |
|---|
| 190 | <cfchartdata item="#t#" value="#data.true#"> |
|---|
| 191 | </cfchartseries> |
|---|
| 192 | </cfchart> |
|---|
| 193 | <cfset currentColorIndex = currentColorIndex + 1> |
|---|
| 194 | </cfcase> |
|---|
| 195 | |
|---|
| 196 | <cfcase value="multiple choice (single selection),Multiple Choice (Multi Selection) with Other,Multiple Choice (Single Selection) with Other,Multiple Choice (Multi Selection)"> |
|---|
| 197 | <cfset answers = application.question.getAnswers(id)> |
|---|
| 198 | |
|---|
| 199 | <cfif cfmx7> |
|---|
| 200 | |
|---|
| 201 | <cfinclude template="stats_mc.cfm"> |
|---|
| 202 | |
|---|
| 203 | <cfelse> |
|---|
| 204 | |
|---|
| 205 | <cfchart format="flash" chartWidth="575" chartHeight="575" |
|---|
| 206 | rotated="yes" gridlines="#max+1#"> |
|---|
| 207 | <cfchartseries type="bar" paintStyle="raise" seriesColor="#currentColor#"> |
|---|
| 208 | <cfif structKeyExists(data,"other")> |
|---|
| 209 | <cfchartdata item="Other" value="#data.other#"> |
|---|
| 210 | </cfif> |
|---|
| 211 | <cfloop query="answers"> |
|---|
| 212 | <cfchartdata item="#answer#" value="#data[id]#"> |
|---|
| 213 | </cfloop> |
|---|
| 214 | </cfchartseries> |
|---|
| 215 | <cfset currentColorIndex = currentColorIndex + 1> |
|---|
| 216 | </cfchart> |
|---|
| 217 | |
|---|
| 218 | </cfif> |
|---|
| 219 | |
|---|
| 220 | <cfif findNoCase("other",questiontype)> |
|---|
| 221 | <cfoutput> |
|---|
| 222 | <p> |
|---|
| 223 | <a href="javascript:popup('otherviewer.cfm?questionidfk=#id#')">View Other Results</a> |
|---|
| 224 | </p> |
|---|
| 225 | </cfoutput> |
|---|
| 226 | </cfif> |
|---|
| 227 | |
|---|
| 228 | </cfcase> |
|---|
| 229 | |
|---|
| 230 | <cfcase value="text box (single),text box (multi)"> |
|---|
| 231 | <cfoutput> |
|---|
| 232 | <a href="javascript:popup('textviewer.cfm?questionidfk=#id#')">View Answers</a> |
|---|
| 233 | </cfoutput> |
|---|
| 234 | </cfcase> |
|---|
| 235 | |
|---|
| 236 | <cfcase value="matrix"> |
|---|
| 237 | |
|---|
| 238 | <cfset sortedAnswers = data.sortedAnswers> |
|---|
| 239 | <cfset structDelete(data, "sortedAnswers")> |
|---|
| 240 | <cfset sortedItems = data.sortedItems> |
|---|
| 241 | <cfset structDelete(data, "sortedItems")> |
|---|
| 242 | |
|---|
| 243 | <cfif cfmx7> |
|---|
| 244 | |
|---|
| 245 | <cfinclude template="stats_matrix.cfm"> |
|---|
| 246 | |
|---|
| 247 | <cfelse> |
|---|
| 248 | |
|---|
| 249 | <cfchart format="flash" chartWidth="575" chartHeight="575" rotated="yes" show3d=true showLegend=true> |
|---|
| 250 | <cfloop list="#sortedItems#" index="item"> |
|---|
| 251 | <cfset label = data[item].label> |
|---|
| 252 | <cfchartseries type="bar" paintStyle="raise" seriesColor="#currentColor#" seriesLabel="#label#"> |
|---|
| 253 | <cfloop list="#sortedAnswers#" index="v"> |
|---|
| 254 | <cfif v is not "label"> |
|---|
| 255 | <cfchartdata item="#data[item][v].label#" value="#data[item][v].count#"> |
|---|
| 256 | </cfif> |
|---|
| 257 | </cfloop> |
|---|
| 258 | </cfchartseries> |
|---|
| 259 | <cfset currentColorIndex = currentColorIndex + 1> |
|---|
| 260 | <cfif currentColorIndex gt listLen(colorList)> |
|---|
| 261 | <cfset currentColorIndex = 1> |
|---|
| 262 | </cfif> |
|---|
| 263 | <cfset currentColor = listGetAt(colorList, currentColorIndex)> |
|---|
| 264 | </cfloop> |
|---|
| 265 | </cfchart> |
|---|
| 266 | |
|---|
| 267 | </cfif> |
|---|
| 268 | |
|---|
| 269 | <cfset currentColorIndex = currentColorIndex + 1> |
|---|
| 270 | </cfcase> |
|---|
| 271 | |
|---|
| 272 | <cfdefaultcase> |
|---|
| 273 | <!--- This should not happen ---> |
|---|
| 274 | </cfdefaultcase> |
|---|
| 275 | |
|---|
| 276 | </cfswitch> |
|---|
| 277 | |
|---|
| 278 | <cfif currentColorIndex gt listLen(colorList)> |
|---|
| 279 | <cfset currentColorIndex = 1> |
|---|
| 280 | </cfif> |
|---|
| 281 | |
|---|
| 282 | </td> |
|---|
| 283 | </tr> |
|---|
| 284 | </table> |
|---|
| 285 | </p> |
|---|
| 286 | </cfoutput> |
|---|
| 287 | </cfloop> |
|---|
| 288 | |
|---|
| 289 | </tags:layout> |
|---|
| 290 | |
|---|
| 291 | <!--- handles both excel and pdf ---> |
|---|
| 292 | <cfelse> |
|---|
| 293 | |
|---|
| 294 | <!--- |
|---|
| 295 | Excel Generation |
|---|
| 296 | It's like the Pepsi Generation - but not as cool. And not in a can. |
|---|
| 297 | |
|---|
| 298 | So, I'm going to use queries here. Normally I'd do everything via the CFC. |
|---|
| 299 | This is so special though I think it may make more sense here. |
|---|
| 300 | Then again, I may just be lazy. |
|---|
| 301 | But does anyone actually even look at the source code? |
|---|
| 302 | I doubt it. |
|---|
| 303 | Either way. |
|---|
| 304 | Just know I really wanted to put this in the CFC. |
|---|
| 305 | I feel really bad about it. |
|---|
| 306 | But I'll live. |
|---|
| 307 | ---> |
|---|
| 308 | |
|---|
| 309 | <!--- step one. get all users who responded ---> |
|---|
| 310 | <cfquery name="getSurveyTakers" datasource="#application.settings.dsn#"> |
|---|
| 311 | select ownerid, completed |
|---|
| 312 | from #application.settings.tableprefix#survey_results |
|---|
| 313 | where surveyidfk = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" maxlength="35" value="#form.surveyidfk#"> |
|---|
| 314 | </cfquery> |
|---|
| 315 | |
|---|
| 316 | <!--- output headers for excel ---> |
|---|
| 317 | <cfsavecontent variable="report"> |
|---|
| 318 | <cfoutput><table border="1" width="100%"></cfoutput> |
|---|
| 319 | |
|---|
| 320 | <cfoutput><tr><td>Survey Taker ID</td><td>Survey Taken</td><cfloop query="questions"><td>#question#</td></cfloop></tr></cfoutput> |
|---|
| 321 | |
|---|
| 322 | <cfloop query="getSurveyTakers"> |
|---|
| 323 | |
|---|
| 324 | <cfset answerRow = ""> |
|---|
| 325 | <cfset oid = ownerid> |
|---|
| 326 | <cfloop query="questions"> |
|---|
| 327 | <cfset answerRow = answerRow & "<td>" & application.survey.getAnswerResult(id,oid) & "</td>"> |
|---|
| 328 | </cfloop> |
|---|
| 329 | |
|---|
| 330 | <cfoutput><tr><td>#ownerid#</td><td>#dateFormat(completed,"mm/dd/yy")# #timeFormat(completed,"h:mm tt")#</td>#answerRow#</tr></cfoutput> |
|---|
| 331 | </cfloop> |
|---|
| 332 | |
|---|
| 333 | <cfoutput></table></cfoutput> |
|---|
| 334 | </cfsavecontent> |
|---|
| 335 | |
|---|
| 336 | |
|---|
| 337 | <cfif form.format is "excel"> |
|---|
| 338 | <cfcontent type="application/msexcel"> |
|---|
| 339 | <cfheader name="content-disposition" value="attachment;filename=report.xls"> |
|---|
| 340 | <cfoutput>#report#</cfoutput> |
|---|
| 341 | <cfabort> |
|---|
| 342 | </cfif> |
|---|
| 343 | |
|---|
| 344 | <cfif form.format is "pdf"> |
|---|
| 345 | <cfcontent type="application/pdf"> |
|---|
| 346 | <cfheader name="content-disposition" value="attachment;filename=report.pdf"> |
|---|
| 347 | <cfdocument format="pdf" orientation="landscape"> |
|---|
| 348 | <cfoutput>#report#</cfoutput> |
|---|
| 349 | </cfdocument> |
|---|
| 350 | </cfif> |
|---|
| 351 | |
|---|
| 352 | </cfif> |
|---|
| 353 | |
|---|
| 354 | </cfif> |
|---|
| 355 | |
|---|
| 356 | <cfsetting enablecfoutputonly=false> |
|---|