| 1 | <cfsetting enablecfoutputonly=true> |
|---|
| 2 | <!--- |
|---|
| 3 | Name : messages_edit.cfm |
|---|
| 4 | Author : Raymond Camden |
|---|
| 5 | Created : July 5, 2004 |
|---|
| 6 | Last Updated : November 6, 2006 |
|---|
| 7 | History : Simple size change (rkc 7/27/06) |
|---|
| 8 | : Attachments support (rkc 11/6/06) |
|---|
| 9 | Purpose : |
|---|
| 10 | |
|---|
| 11 | Note: In the admin I don't let folks upload attachments, but |
|---|
| 12 | I do let them remove them. |
|---|
| 13 | ---> |
|---|
| 14 | |
|---|
| 15 | <cfif isDefined("form.cancel") or not isDefined("url.id") or not len(url.id)> |
|---|
| 16 | <cflocation url="messages.cfm" addToken="false"> |
|---|
| 17 | </cfif> |
|---|
| 18 | |
|---|
| 19 | <!--- get all threads ---> |
|---|
| 20 | <cfset threads = application.galleon.thread.getThreads(false)> |
|---|
| 21 | |
|---|
| 22 | <!--- get all users ---> |
|---|
| 23 | <cfset users = application.galleon.user.getUsers()> |
|---|
| 24 | |
|---|
| 25 | <cfif isDefined("form.save")> |
|---|
| 26 | <cfset errors = ""> |
|---|
| 27 | <cfif not len(trim(form.title))> |
|---|
| 28 | <cfset errors = errors & "You must specify a title.<br>"> |
|---|
| 29 | </cfif> |
|---|
| 30 | <cfif not len(trim(form.body))> |
|---|
| 31 | <cfset errors = errors & "You must specify a body.<br>"> |
|---|
| 32 | </cfif> |
|---|
| 33 | <cfif not len(trim(form.posted)) or not isDate(form.posted)> |
|---|
| 34 | <cfset errors = errors & "You must specify a valid creation date.<br>"> |
|---|
| 35 | </cfif> |
|---|
| 36 | |
|---|
| 37 | <cfif not len(errors)> |
|---|
| 38 | |
|---|
| 39 | <cfif structKeyExists(form, "removefile") and isDefined("message.attachment") and fileExists(application.galleon.settings.attachmentdir & "/" & message.filename)> |
|---|
| 40 | <cffile action="delete" file="#application.galleon.settings.attachmentdir#/#message.filename#"> |
|---|
| 41 | <cfelseif isDefined("message.attachment")> |
|---|
| 42 | <cfset attachment = message.attachment> |
|---|
| 43 | <cfset filename = message.filename> |
|---|
| 44 | </cfif> |
|---|
| 45 | |
|---|
| 46 | <cfset message = structNew()> |
|---|
| 47 | |
|---|
| 48 | <cfset message.title = trim(htmlEditFormat(form.title))> |
|---|
| 49 | <cfset message.body = trim(htmlEditFormat(form.body))> |
|---|
| 50 | <cfset message.posted = trim(form.posted)> |
|---|
| 51 | <cfset message.threadidfk = form.threadidfk> |
|---|
| 52 | <cfset message.useridfk = form.useridfk> |
|---|
| 53 | <cfif structKeyExists(variables, "attachment")> |
|---|
| 54 | <cfset message.attachment = attachment> |
|---|
| 55 | <cfset message.filename = filename> |
|---|
| 56 | <cfelse> |
|---|
| 57 | <cfset message.attachment = ""> |
|---|
| 58 | <cfset message.filename = ""> |
|---|
| 59 | </cfif> |
|---|
| 60 | |
|---|
| 61 | <cfif url.id neq 0> |
|---|
| 62 | <cfset application.galleon.message.saveMessage(url.id, message)> |
|---|
| 63 | <cfelse> |
|---|
| 64 | <cfset threadPicked = application.galleon.thread.getThread(form.threadidfk)> |
|---|
| 65 | <!--- translate the user id to the username for addMessage ---> |
|---|
| 66 | <cfloop query="users"> |
|---|
| 67 | <cfif id is form.useridfk> |
|---|
| 68 | <cfset theusername = username> |
|---|
| 69 | </cfif> |
|---|
| 70 | </cfloop> |
|---|
| 71 | <cfset application.galleon.message.addMessage(message,threadPicked.forumidfk,theusername,form.threadidfk)> |
|---|
| 72 | </cfif> |
|---|
| 73 | <cfset msg = "Message, #message.title#, has been updated."> |
|---|
| 74 | <cflocation url="messages.cfm?msg=#urlEncodedFormat(msg)#"> |
|---|
| 75 | </cfif> |
|---|
| 76 | </cfif> |
|---|
| 77 | |
|---|
| 78 | <!--- get message if not new ---> |
|---|
| 79 | <cfif url.id neq 0> |
|---|
| 80 | <cfset message = application.galleon.message.getMessage(url.id)> |
|---|
| 81 | <cfparam name="form.title" default="#message.title#"> |
|---|
| 82 | <cfparam name="form.body" default="#message.body#"> |
|---|
| 83 | <cfparam name="form.posted" default="#dateFormat(message.posted,"m/dd/yy")# #timeFormat(message.posted,"h:mm tt")#"> |
|---|
| 84 | <cfparam name="form.useridfk" default="#message.useridfk#"> |
|---|
| 85 | <cfparam name="form.threadidfk" default="#message.threadidfk#"> |
|---|
| 86 | <cfelse> |
|---|
| 87 | <cfparam name="form.title" default=""> |
|---|
| 88 | <cfparam name="form.body" default=""> |
|---|
| 89 | <cfparam name="form.posted" default="#dateFormat(now(),"m/dd/yy")# #timeFormat(now(),"h:mm tt")#"> |
|---|
| 90 | <cfparam name="form.useridfk" default=""> |
|---|
| 91 | <cfparam name="form.threadidfk" default=""> |
|---|
| 92 | </cfif> |
|---|
| 93 | |
|---|
| 94 | <cfmodule template="../tags/layout.cfm" templatename="admin" title="Message Editor"> |
|---|
| 95 | |
|---|
| 96 | <cfoutput> |
|---|
| 97 | <p> |
|---|
| 98 | <cfif isDefined("errors")><ul><b>#errors#</b></ul></cfif> |
|---|
| 99 | <form action="#cgi.script_name#?#cgi.query_string#" method="post"> |
|---|
| 100 | <table width="100%" cellspacing=0 cellpadding=5 class="adminEditTable"> |
|---|
| 101 | <tr valign="top"> |
|---|
| 102 | <td align="right"><b>Title:</b></td> |
|---|
| 103 | <td><input type="text" name="title" value="#form.title#" size="100"></td> |
|---|
| 104 | </tr> |
|---|
| 105 | <tr valign="top"> |
|---|
| 106 | <td align="right"><b>Body:</b></td> |
|---|
| 107 | <td> |
|---|
| 108 | <textarea name="body" cols=50 rows=20>#form.body#</textarea> |
|---|
| 109 | </td> |
|---|
| 110 | </tr> |
|---|
| 111 | <cfif isDefined("message.attachment") and len(message.attachment)> |
|---|
| 112 | <tr valign="top"> |
|---|
| 113 | <td align="right"><b>Attachment:</b></td> |
|---|
| 114 | <td><a href="../attachment.cfm?id=#url.id#">#message.attachment#</a> |
|---|
| 115 | <br><input type="checkbox" name="removefile">Remove File</a></td> |
|---|
| 116 | </tr> |
|---|
| 117 | </cfif> |
|---|
| 118 | <tr valign="top"> |
|---|
| 119 | <td align="right"><b>Thread:</b></td> |
|---|
| 120 | <td> |
|---|
| 121 | <select name="threadidfk"> |
|---|
| 122 | <cfloop query="threads"> |
|---|
| 123 | <option value="#id#" <cfif form.threadidfk is id>selected</cfif>>#name#</option> |
|---|
| 124 | </cfloop> |
|---|
| 125 | </select> |
|---|
| 126 | </td> |
|---|
| 127 | </tr> |
|---|
| 128 | <tr valign="top"> |
|---|
| 129 | <td align="right"><b>Posted:</b></td> |
|---|
| 130 | <td><input type="text" name="posted" value="#form.posted#" size="50"></td> |
|---|
| 131 | </tr> |
|---|
| 132 | <tr valign="top"> |
|---|
| 133 | <td align="right"><b>User:</b></td> |
|---|
| 134 | <td> |
|---|
| 135 | <select name="useridfk"> |
|---|
| 136 | <cfloop query="users"> |
|---|
| 137 | <option value="#id#" <cfif form.useridfk is id>selected</cfif>>#username#</option> |
|---|
| 138 | </cfloop> |
|---|
| 139 | </select> |
|---|
| 140 | </td> |
|---|
| 141 | </tr> |
|---|
| 142 | <tr> |
|---|
| 143 | <td> </td> |
|---|
| 144 | <td><input type="submit" name="save" value="Save"> <input type="submit" name="cancel" value="Cancel"></td> |
|---|
| 145 | </tr> |
|---|
| 146 | </table> |
|---|
| 147 | </form> |
|---|
| 148 | </p> |
|---|
| 149 | </cfoutput> |
|---|
| 150 | |
|---|
| 151 | </cfmodule> |
|---|
| 152 | |
|---|
| 153 | <cfsetting enablecfoutputonly=false> |
|---|