root/trunk/website/forums/message_edit.cfm @ 8

Revision 5, 5.6 kB (checked in by DanWilson, 17 years ago)

Initial Commit Of ModelGlue? Website (upgrade to blogcfc 511)

Line 
1<cfsetting enablecfoutputonly=true>
2<!---
3        Name         : message_edit.cfm
4        Author       : Raymond Camden
5        Created      : July 6, 2004
6        Last Updated : May 1, 2007
7        History      : Removed mappings (rkc 8/29/05)
8                                 : title+cfcatch change (rkc 8/4/06)
9                                 : attachment support (rkc 11/3/06)
10                                 : fix bug if attachments turned off (rkc 11/14/06)
11                                   Changed calls to isUserInAnyRole to isTheUserInAnyRole (rkc 5/1/07)                                                                                                                                   
12        Purpose          : Allows moderators/admins to edit post.
13--->
14
15<cfif not request.udf.isLoggedOn() or not application.galleon.utils.isTheUserInAnyRole("forumsadmin,forumsmoderator")>
16        <cflocation url="index.cfm" addToken="false">
17</cfif>
18
19<cfif not isDefined("url.id") or not len(url.id)>
20        <cflocation url="index.cfm" addToken="false">
21</cfif>
22
23<!--- get parents --->
24<cftry>
25        <cfset request.message = application.galleon.message.getMessage(url.id)>
26        <cfset request.thread = application.galleon.thread.getThread(request.message.threadidfk)>
27        <cfset request.forum = application.galleon.forum.getForum(request.thread.forumidfk)>
28        <cfset request.conference = application.galleon.conference.getConference(request.forum.conferenceidfk)>
29        <cfcatch>
30                <cflocation url="index.cfm" addToken="false">
31        </cfcatch>
32</cftry>
33
34<cfparam name="form.title" default="#request.message.title#">
35<cfparam name="form.body" default="#request.message.body#">
36<cfparam name="form.oldattachment" default="#request.message.attachment#">
37<cfparam name="form.filename" default="#request.message.filename#">
38<cfparam name="form.attachment" default="">
39
40<cfif isDefined("form.post")>
41        <cfset errors = "">
42        <!--- clean the fields --->
43        <cfset form.title = trim(htmlEditFormat(form.title))>
44        <cfset form.body = trim(form.body)>
45       
46        <cfif not len(form.title)>
47                <cfset errors = errors & "You must enter a title.<br>">
48        </cfif>
49       
50        <cfif not len(form.body)>
51                <cfset errors = errors & "You must enter a body.<br>">
52        </cfif>
53
54        <cfif len(form.title) gt 50>
55                <cfset errors = errors & "Your title is too long.<br>">
56        </cfif>
57       
58        <cfif isBoolean(request.forum.attachments) and request.forum.attachments and len(trim(form.attachment))>
59                <cffile action="upload" destination="#expandPath("./attachments")#" filefield="attachment" nameConflict="makeunique">
60               
61                <cfif cffile.fileWasSaved>
62                        <!--- Is the extension allowed? --->
63                        <cfset newFileName = cffile.serverDirectory & "/" & cffile.serverFile>
64                        <cfset newExtension = cffile.serverFileExt>
65                       
66                        <cfif not listFindNoCase(application.galleon.settings.safeExtensions, newExtension)>
67                                <cfset errors = errors & "Your file did not have a extension. Allowed extensions are: #application.galleon.settings.safeExtensions#.<br>">
68                                <cffile action="delete" file="#newFilename#">
69                                <cfset form.attachment = "">
70                                <cfset form.filename = "">
71                        <cfelse>
72                                <cfset form.oldattachment = cffile.clientFile>
73                                <cfset form.attachment = cffile.clientFile>
74                                <cfset form.filename = cffile.serverFile>
75                        </cfif>
76                </cfif>
77        <cfelseif structKeyExists(form, "removefile")>
78                <cfset form.attachment = "">
79                <cffile action="delete" file="#application.galleon.settings.attachmentdir#/#form.filename#">
80                <cfset form.filename = "">
81        <cfelseif len(form.oldattachment)>
82                <cfset form.attachment = form.oldattachment>
83        </cfif>
84       
85        <cfif not len(errors)>
86                <cfset message = structNew()>
87                <cfset message.title = trim(htmlEditFormat(form.title))>
88                <cfset message.body = trim(form.body)>
89                <cfset message.attachment = form.attachment>
90                <cfset message.filename = form.filename>
91                <cfset message.posted = request.message.posted>
92                <cfset message.threadidfk = request.message.threadidfk>
93                <cfset message.useridfk = request.message.useridfk>
94                <cfset application.galleon.message.saveMessage(url.id, message)>
95                <cflocation url="messages.cfm?threadid=#message.threadidfk#" addToken="false">
96        </cfif>
97</cfif>
98
99<!--- Loads header --->
100<cfmodule template="tags/layout.cfm" templatename="main" title="#application.galleon.settings.title# : Edit Post">
101
102<cfoutput>
103<p>
104<table width="500" cellpadding="6" class="tableDisplay" cellspacing="1" border="0">
105        <tr class="tableHeader">
106                <td class="tableHeader">Edit Post</td>
107        </tr>
108        <cfif isDefined("errors")>
109        <tr class="tableRowMain">
110                <td>
111                Please correct the following error(s):<ul><b>#errors#</b></ul>
112                </td>
113        </tr>
114        </cfif>
115        <tr class="tableRowMain">
116                <td>
117                <form action="#cgi.script_name#?#cgi.query_string#" method="post" enctype="multipart/form-data">
118                <input type="hidden" name="post" value="1">
119
120                <table>
121                        <tr>
122                                <td><b>Title: </b></td>
123                                <td><input type="text" name="title" value="#form.title#" class="formBox" maxlength="50"></td>
124                        </tr>
125                        <tr>
126                                <td colspan="2"><b>Body: </b><br>
127                                <textarea name="body" cols="50" rows="20">#form.body#</textarea></td>
128                        </tr>
129                        <cfif isBoolean(request.forum.attachments) and request.forum.attachments>
130                                <tr valign="top">
131                                        <td><b>Attach File:</b></td>
132                                        <td>
133                                        <input type="file" name="attachment">
134                                        <cfif len(form.oldattachment)>
135                                        <input type="hidden" name="oldattachment" value="#form.oldattachment#">
136                                        <input type="hidden" name="filename" value="#form.filename#">
137                                        <br>
138                                        File already attached: #form.oldattachment#<br>
139                                        <input type="checkbox" name="removefile"> Remove Attachment
140                                        </cfif>
141                                        </td>
142                                </tr>
143                        </cfif>                         
144                       
145                        <tr>
146                                <td>&nbsp;</td>
147                                <td align="right"><input type="image" src="images/btn_update.gif" alt="Update" title="Update" width="59" height="19" name="post"></td>
148                        </tr>
149                </table>
150                </form>
151                </td>
152        </tr>
153</table>
154</p>
155</cfoutput>
156
157</cfmodule>
158
159<cfsetting enablecfoutputonly=false>
Note: See TracBrowser for help on using the browser.