| [5] | 1 | <cfsetting enablecfoutputonly=true> |
|---|
| 2 | <!--- |
|---|
| 3 | Name : survey_edit.cfm |
|---|
| 4 | Author : Raymond Camden |
|---|
| 5 | Created : September 7, 2004 |
|---|
| 6 | Last Updated : March 30, 2006 |
|---|
| 7 | History : support for clearing results (rkc 3/30/06) |
|---|
| 8 | ---> |
|---|
| 9 | <cfimport taglib="../tags/" prefix="tags"> |
|---|
| 10 | |
|---|
| 11 | <cfif isDefined("form.cancel") or not isDefined("url.id")> |
|---|
| 12 | <cflocation url="surveys.cfm" addToken="false"> |
|---|
| 13 | </cfif> |
|---|
| 14 | |
|---|
| 15 | <cfif isDefined("form.save")> |
|---|
| 16 | <cfset form = request.udf.cleanStruct(form)> |
|---|
| 17 | <cfset errors = ""> |
|---|
| 18 | <cfif not len(form.name)> |
|---|
| 19 | <cfset errors = errors & "You must specify a name.<br>"> |
|---|
| 20 | </cfif> |
|---|
| 21 | <cfif not len(form.description)> |
|---|
| 22 | <cfset errors = errors & "You must specify a description.<br>"> |
|---|
| 23 | </cfif> |
|---|
| 24 | <cfif len(form.dateBegin) and not isDate(form.dateBegin)> |
|---|
| 25 | <cfset errors = errors & "If you specify a survey starting date, it must be a valid date.<br>"> |
|---|
| 26 | </cfif> |
|---|
| 27 | <cfif len(form.dateEnd) and not isDate(form.dateEnd)> |
|---|
| 28 | <cfset errors = errors & "If you specify a survey ending date, it must be a valid date.<br>"> |
|---|
| 29 | </cfif> |
|---|
| 30 | <cfif len(form.dateBegin) and isDate(form.dateBegin) and len(form.dateEnd) and isDate(form.dateEnd) |
|---|
| 31 | and dateCompare(form.dateBegin,form.dateEnd,"s") gte 0> |
|---|
| 32 | <cfset errors = errors & "If you specify a survey starting and ending date, the start date must be before the ending date.<br>"> |
|---|
| 33 | </cfif> |
|---|
| 34 | <cfif len(form.resultMailTo) and not request.udf.isEmail(form.resultMailTo)> |
|---|
| 35 | <cfset errors = errors & "The value to send results to must be a valid email address.<br>"> |
|---|
| 36 | </cfif> |
|---|
| 37 | <cfif form.active> |
|---|
| 38 | <cfif url.id eq 0> |
|---|
| 39 | <cfset errors = errors & "A new survey cannot be active. You must first add questions.<br>"> |
|---|
| 40 | <cfelse> |
|---|
| 41 | <!--- get questions ---> |
|---|
| 42 | <cfset q = application.question.getQuestions(url.id)> |
|---|
| 43 | <cfif q.recordCount is 0> |
|---|
| 44 | <cfset errors = errors & "This survey cannot be marked active until questions are added.<br>"> |
|---|
| 45 | </cfif> |
|---|
| 46 | </cfif> |
|---|
| 47 | </cfif> |
|---|
| 48 | |
|---|
| 49 | <!--- Nuke the old list ---> |
|---|
| 50 | <cfif isDefined("form.nukeEL")> |
|---|
| 51 | <cfset application.survey.resetEmailList(url.id)> |
|---|
| 52 | </cfif> |
|---|
| 53 | |
|---|
| 54 | <cfif not len(errors)> |
|---|
| 55 | |
|---|
| 56 | <cfset data = structNew()> |
|---|
| 57 | <cfset data.name = form.name> |
|---|
| 58 | <cfset data.description = form.description> |
|---|
| 59 | <cfset data.active = form.active> |
|---|
| 60 | <cfif isDate(form.dateBegin)> |
|---|
| 61 | <cfset data.dateBegin = form.dateBegin> |
|---|
| 62 | </cfif> |
|---|
| 63 | <cfif isDate(form.dateEnd)> |
|---|
| 64 | <cfset data.dateEnd = form.dateEnd> |
|---|
| 65 | </cfif> |
|---|
| 66 | <cfset data.resultMailTo = form.resultMailTo> |
|---|
| 67 | <cfset data.surveyPassword = form.surveyPassword> |
|---|
| 68 | <cfset data.thankYouMsg = form.thankYouMsg> |
|---|
| 69 | |
|---|
| 70 | <cfif url.id neq 0> |
|---|
| 71 | <cfset data.id = url.id> |
|---|
| 72 | <cfset application.survey.updateSurvey(argumentCollection=data)> |
|---|
| 73 | <cfelse> |
|---|
| 74 | <cfset url.id = application.survey.addSurvey(argumentCollection=data)> |
|---|
| 75 | </cfif> |
|---|
| 76 | |
|---|
| 77 | <cfif len(trim(form.emailList))> |
|---|
| 78 | <cfset emails = arrayNew(1)> |
|---|
| 79 | <cffile action="UPLOAD" filefield="form.emailList" destination="#expandPath("./uploads")#" nameconflict="MAKEUNIQUE"> |
|---|
| 80 | <cfset theFile = cffile.serverDirectory & "/" & cffile.serverFile> |
|---|
| 81 | <cffile action="read" file="#theFile#" variable="buffer"> |
|---|
| 82 | <!--- attempt to read the buffer ---> |
|---|
| 83 | <cfloop index="line" list="#buffer#" delimiters="#chr(10)#"> |
|---|
| 84 | <cfif len(trim(line)) and request.udf.isEmail(trim(line))> |
|---|
| 85 | <cfset arrayAppend(emails, trim(line))> |
|---|
| 86 | </cfif> |
|---|
| 87 | </cfloop> |
|---|
| 88 | <cfset application.survey.resetEmailList(url.id)> |
|---|
| 89 | <cfif arrayLen(emails)> |
|---|
| 90 | <cfset application.survey.addEmailList(url.id,emails)> |
|---|
| 91 | </cfif> |
|---|
| 92 | <!--- cleanup ---> |
|---|
| 93 | <cffile action="delete" file="#theFile#"> |
|---|
| 94 | </cfif> |
|---|
| 95 | |
|---|
| 96 | <cfset msg = "Survey, #form.name#, has been updated."> |
|---|
| 97 | <cflocation url="surveys.cfm?msg=#urlEncodedFormat(msg)#"> |
|---|
| 98 | </cfif> |
|---|
| 99 | </cfif> |
|---|
| 100 | |
|---|
| 101 | <cfif isDefined("form.dupe") and url.id neq 0> |
|---|
| 102 | <cfset application.survey.duplicateSurvey(url.id)> |
|---|
| 103 | <cfset msg = "Survey, #form.name#, has been duplicated."> |
|---|
| 104 | <cflocation url="surveys.cfm?msg=#urlEncodedFormat(msg)#"> |
|---|
| 105 | </cfif> |
|---|
| 106 | |
|---|
| 107 | <cfif isDefined("form.clear") and url.id neq 0> |
|---|
| 108 | <cfset application.survey.clearResults(url.id)> |
|---|
| 109 | <cfset msg = "Survey, #form.name#, has had its results cleared."> |
|---|
| 110 | <cflocation url="surveys.cfm?msg=#urlEncodedFormat(msg)#"> |
|---|
| 111 | </cfif> |
|---|
| 112 | |
|---|
| 113 | <!--- get survey if not new ---> |
|---|
| 114 | <cfif url.id neq 0> |
|---|
| 115 | <cfset survey = application.survey.getSurvey(url.id)> |
|---|
| 116 | <cfset emailList = application.survey.getEmailList(url.id)> |
|---|
| 117 | <cfparam name="form.name" default="#survey.name#"> |
|---|
| 118 | <cfparam name="form.description" default="#survey.description#"> |
|---|
| 119 | <cfparam name="form.active" default="#survey.active#"> |
|---|
| 120 | <cfparam name="form.dateBegin" default="#survey.dateBegin#"> |
|---|
| 121 | <cfparam name="form.dateEnd" default="#survey.dateEnd#"> |
|---|
| 122 | <cfparam name="form.resultMailTo" default="#survey.resultMailTo#"> |
|---|
| 123 | <cfparam name="form.surveyPassword" default="#survey.surveyPassword#"> |
|---|
| 124 | <cfparam name="form.thankYouMsg" default="#survey.thankYouMsg#"> |
|---|
| 125 | |
|---|
| 126 | <cfelse> |
|---|
| 127 | <cfparam name="form.name" default=""> |
|---|
| 128 | <cfparam name="form.description" default=""> |
|---|
| 129 | <cfparam name="form.active" default="false"> |
|---|
| 130 | <cfparam name="form.dateBegin" default=""> |
|---|
| 131 | <cfparam name="form.dateEnd" default=""> |
|---|
| 132 | <cfparam name="form.resultMailTo" default=""> |
|---|
| 133 | <cfparam name="form.surveyPassword" default=""> |
|---|
| 134 | <cfparam name="form.thankYouMsg" default=""> |
|---|
| 135 | |
|---|
| 136 | </cfif> |
|---|
| 137 | |
|---|
| 138 | <tags:layout templatename="admin" title="Survey Editor"> |
|---|
| 139 | |
|---|
| 140 | <cfoutput> |
|---|
| 141 | <script> |
|---|
| 142 | function viewEmailList() { |
|---|
| 143 | window.open("viewemaillist.cfm?id=#url.id#","viewEmailList","width=500,height=600"); |
|---|
| 144 | } |
|---|
| 145 | </script> |
|---|
| 146 | |
|---|
| 147 | <p> |
|---|
| 148 | Please use the form below to enter details about the survey. All required fields are marked (*). The values |
|---|
| 149 | for date survey begins and ends allows you to restrict by date when surveys can be answered. If a survey password |
|---|
| 150 | is set, then it must be provided before the user can take the survey. |
|---|
| 151 | </p> |
|---|
| 152 | |
|---|
| 153 | <p> |
|---|
| 154 | <cfif isDefined("errors")><ul><b>#errors#</b></ul></cfif> |
|---|
| 155 | <form action="#cgi.script_name#?#cgi.query_string#" method="post" enctype="multipart/form-data"> |
|---|
| 156 | <table cellspacing=0 cellpadding=5 class="adminEditTable" width="100%"> |
|---|
| 157 | <tr valign="top"> |
|---|
| 158 | <td width="200"><b>(*) Name:</b></td> |
|---|
| 159 | <td><input type="text" name="name" value="#form.name#" size="50"></td> |
|---|
| 160 | </tr> |
|---|
| 161 | <tr valign="top"> |
|---|
| 162 | <td><b>(*) Description:</b></td> |
|---|
| 163 | <td><textarea name="description" rows=6 cols=35 wrap="soft">#form.description#</textarea></td> |
|---|
| 164 | </tr> |
|---|
| 165 | <tr valign="top"> |
|---|
| 166 | <td><b>Message Displayed at End:</b></td> |
|---|
| 167 | <td><textarea name="thankyoumsg" rows=6 cols=35 wrap="soft">#form.thankyoumsg#</textarea></td> |
|---|
| 168 | </tr> |
|---|
| 169 | |
|---|
| 170 | <tr valign="top"> |
|---|
| 171 | <td><b>(*) Active:</b></td> |
|---|
| 172 | <td><select name="active"> |
|---|
| 173 | <option value="1" <cfif form.active>selected</cfif>>Yes</option> |
|---|
| 174 | <option value="0" <cfif not form.active>selected</cfif>>No</option> |
|---|
| 175 | </select></td> |
|---|
| 176 | </tr> |
|---|
| 177 | <tr valign="top"> |
|---|
| 178 | <td><b>Date Survey Begins:</b></td> |
|---|
| 179 | <td><input type="text" name="dateBegin" value="#dateFormat(form.dateBegin)# #timeFormat(form.dateBegin)#" size="50"></td> |
|---|
| 180 | </tr> |
|---|
| 181 | <tr valign="top"> |
|---|
| 182 | <td><b>Date Survey Ends:</b></td> |
|---|
| 183 | <td><input type="text" name="dateEnd" value="#dateFormat(form.dateEnd)# #timeFormat(form.dateEnd)#" size="50"></td> |
|---|
| 184 | </tr> |
|---|
| 185 | <tr valign="top"> |
|---|
| 186 | <td><b>Mail Results To:</b></td> |
|---|
| 187 | <td><input type="text" name="resultMailTo" value="#form.resultMailTo#" size="50"></td> |
|---|
| 188 | </tr> |
|---|
| 189 | <tr valign="top"> |
|---|
| 190 | <td><b>Survey Password:</b></td> |
|---|
| 191 | <td><input type="text" name="surveyPassword" value="#form.surveyPassword#" size="50"></td> |
|---|
| 192 | </tr> |
|---|
| 193 | <tr> |
|---|
| 194 | <td colspan="2"> |
|---|
| 195 | <b>Email Restriction List:</b><br> |
|---|
| 196 | Along with using a survey password, a survey can be restricted to a set of email addresses. In order to do this, |
|---|
| 197 | you must create a text file of addresses (one per line) and upload it using the field below. This operation will overwrite any |
|---|
| 198 | existing list of email addresses. |
|---|
| 199 | <cfif url.id neq 0> |
|---|
| 200 | This survey currently <b><cfif not emailList.recordCount>does not<cfelse>has</cfif></b> a restricted email list. <cfif emailList.recordCount>You can view this list <a href="javaScript:viewEmailList()">here</a>.</cfif> |
|---|
| 201 | </cfif> |
|---|
| 202 | <br><br> |
|---|
| 203 | <input type="file" name="emailList"> |
|---|
| 204 | <br> |
|---|
| 205 | <input type="checkbox" name="nukeEL"> Remove Current Email List |
|---|
| 206 | </td> |
|---|
| 207 | </tr> |
|---|
| 208 | <tr> |
|---|
| 209 | <td> </td> |
|---|
| 210 | <td><input type="submit" name="save" value="Save"> |
|---|
| 211 | <cfif url.id neq 0> |
|---|
| 212 | <input type="submit" name="dupe" value="Duplicate"> |
|---|
| 213 | <input type="submit" name="clear" value="Clear Results"> |
|---|
| 214 | </cfif> |
|---|
| 215 | <input type="submit" name="cancel" value="Cancel"></td> |
|---|
| 216 | </tr> |
|---|
| 217 | </table> |
|---|
| 218 | </form> |
|---|
| 219 | </p> |
|---|
| 220 | </cfoutput> |
|---|
| 221 | |
|---|
| 222 | </tags:layout> |
|---|
| 223 | |
|---|
| 224 | <cfsetting enablecfoutputonly=false> |
|---|