forked from joedanz/cf-project-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheditFile.cfm
180 lines (163 loc) · 6.6 KB
/
editFile.cfm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<cfsetting enablecfoutputonly="true">
<cfprocessingdirective pageencoding="utf-8">
<cfif StructKeyExists(form,"fileID")> <!--- update file --->
<cfif not compare(form.description,'<br />')>
<cfset form.description = "">
</cfif>
<cfset application.file.update(form.fileID,form.projectid,form.title,form.category,form.description)>
<cfset application.activity.add(createUUID(),form.projectid,session.user.userid,'File',form.fileID,form.title,'edited')>
<cfset application.notify.fileUpdate(form.projectid,form.fileID)>
<cflocation url="files.cfm?p=#form.projectID#" addtoken="false">
<cfelseif StructKeyExists(form,"projectID")> <!--- add/upload file --->
<cftry>
<cfdirectory action="create" directory="#application.userFilesPath##form.projectID#">
<cfcatch></cfcatch>
</cftry>
<cffile action="upload" filefield="fileupload" destination = "#application.userFilesPath##form.projectID#" nameConflict = "MakeUnique">
<cfset newID = createUUID()>
<cfif not compare(form.description,'<br />')>
<cfset form.description = "">
</cfif>
<cfset application.file.add(newID,form.projectID,form.title,form.category,form.description,cffile.ClientFile,cffile.ServerFile,cffile.ClientFileExt,cffile.FileSize,session.user.userid)>
<cfset application.activity.add(createUUID(),form.projectid,session.user.userid,'File',newID,form.title,'added')>
<cfset application.notify.fileNew(form.projectid,newID)>
<cflocation url="files.cfm?p=#form.projectID#" addtoken="false">
</cfif>
<cfif not StructKeyExists(url,'p')>
<cfoutput><h2>No Project Selected!</h2></cfoutput><cfabort>
</cfif>
<cfif session.user.admin>
<cfset project = application.project.get(projectID=url.p)>
<cfelse>
<cfset project = application.project.get(session.user.userid,url.p)>
</cfif>
<cfset categories = application.category.get(url.p,'file')>
<cfif not session.user.admin and not project.file_edit eq 1>
<cfoutput><h2>You do not have permission to <cfif StructKeyExists(url,"f")>edit<cfelse>add</cfif> files!!!</h2></cfoutput>
<cfabort>
</cfif>
<cfparam name="fileupload" default="">
<cfparam name="title" default="">
<cfparam name="catID" default="">
<cfparam name="description" default="">
<cfparam name="title_action" default="Add">
<cfif StructKeyExists(url,"f")>
<cfset thisFile = application.file.get(url.p,url.f)>
<cfset title = thisFile.title>
<cfset catID = thisFile.categoryID>
<cfset description = thisFile.description>
<cfset title_action = "Edit">
</cfif>
<!--- Loads header/footer --->
<cfmodule template="#application.settings.mapping#/tags/layout.cfm" templatename="main" title="#project.name# » #title_action# File" project="#project.name#" projectid="#url.p#" svnurl="#project.svnurl#">
<cfhtmlhead text="<script type='text/javascript'>
function newFileCat(val) {
if (val == 'new') {
var newcat = prompt('Enter the new category name:','');
var opt = new Option(newcat, newcat);
var sel = document.edit.category;
sel.options[sel.options.length] = opt;
sel.selectedIndex = sel.options.length-1;
}
}
function confirmSubmit() {
var errors = '';
var oEditor = FCKeditorAPI.GetInstance('description');
if (document.edit.title.value == '') {errors = errors + ' ** You must enter a title.\n';}
if (document.edit.category.value == '') {errors = errors + ' ** You must select a category.\n';}
if (oEditor.GetHTML() == '') {errors = errors + ' ** You must enter a description.\n';}
if (errors != '') {
alert('Please correct the following errors:\n\n' + errors)
return false;
} else return true;
}
$(document).ready(function(){
$('##title').focus();
});
</script>">
<cfoutput>
<div id="container">
<cfif project.recordCount>
<!--- left column --->
<div class="left">
<div class="main">
<div class="header">
<span class="rightmenu">
<a href="javascript:history.back();" class="cancel">Cancel</a>
</span>
<h2 class="msg"><cfif StructKeyExists(url,"m")>Edit<cfelse>Upload new</cfif> file</h2>
</div>
<div class="content">
<form action="#cgi.script_name#?#cgi.query_string#" method="post" name="edit" id="edit" class="frm pb15" enctype="multipart/form-data" onsubmit="return confirmSubmit();">
<cfif not StructKeyExists(url,"f")>
<p>
<label for="fileupload" class="req">File:</label>
<input type="file" name="fileupload" id="fileupload" value="#fileupload#" />
</p>
</cfif>
<p>
<label for="title" class="req">Title:</label>
<input type="text" name="title" id="title" value="#HTMLEditFormat(title)#" maxlength="120" />
</p>
<p>
<label for="category" class="req">Category:</label>
<select name="category" id="category" onChange="newFileCat(this.value);">
<option value="">Select Category...</option>
<cfloop query="categories">
<option value="#categoryID#"<cfif not compare(catID,categoryID)> selected="selected"</cfif>>#category#</option>
</cfloop>
<option value="new">--- add new category ---</option>
</select>
</p>
<p>
<label for="description" class="req">Description:</label>
<cfif session.mobileBrowser>
<textarea name="description" id="description">#description#</textarea>
<cfelse>
<cfscript>
basePath = 'includes/fckeditor/';
fckEditor = createObject("component", "#basePath#fckeditor");
fckEditor.instanceName = "description";
fckEditor.value = '#description#';
fckEditor.basePath = basePath;
fckEditor.width = 460;
fckEditor.height = 150;
fckEditor.ToolbarSet = "Basic";
fckEditor.create(); // create the editor.
</cfscript>
</cfif>
</p>
<label for="submit"> </label>
<cfif StructKeyExists(url,"f")>
<input type="submit" class="button" name="submit" id="submit" value="Update File" onclick="return confirmSubmit();" />
<input type="hidden" name="fileID" value="#url.f#" />
<cfelse>
<input type="submit" class="button" name="submit" id="submit" value="Upload File" />
</cfif>
<input type="button" class="button" name="cancel" value="Cancel" onclick="history.back();" />
<input type="hidden" name="projectID" value="#url.p#" />
</form>
</div>
</div>
<div class="bottom"> </div>
<div class="footer">
<cfinclude template="footer.cfm">
</div>
</div>
<!--- right column --->
<div class="right">
<!---
<div class="textheader"><h3>Categories</h3></div>
<div class="content">
<ul>
</ul>
</div>
--->
</div>
<cfelse>
<div class="alert">Project Not Found.</div>
</cfif>
</div>
</cfoutput>
</cfmodule>
<cfsetting enablecfoutputonly="false">