root/trunk/website/blog/admin/slideshow.cfm @ 6

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

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

Line 
1<cfsetting enablecfoutputonly=true>
2<cfprocessingdirective pageencoding="utf-8">
3<!---
4        Name         : slideshow.cfm
5        Author       : Raymond Camden
6        Created      : 9/02/06
7        Last Updated : 2/28/07
8        History      : Don't show file upload if new slideshow (rkc 9/6/06)
9                                 : Support for getting folder from CFC (rkc 12/14/06)
10                                 : update to getting right folder (rkc 2/28/07)
11--->
12
13<cfif structKeyExists(form, "cancel")>
14        <cflocation url="slideshows.cfm" addToken="false">
15</cfif>
16
17<cfset dir = application.slideshow.getSlideShowDir()>
18<!--- remove ending /\ --->
19<cfif right(dir,1) is "/" or right(dir,1) is "\">
20        <cfset dir = left(dir, len(dir)-1)>
21</cfif>
22
23<cfif structKeyExists(form, "id")>
24        <cfset url.id = form.id>
25</cfif>
26<!--- kind of a hack based on my datatable tag --->
27<cfif structKeyExists(url, "id") and url.id is 0>
28        <cfset url.id = "">
29</cfif>
30
31<cfparam name="url.id" default="">
32
33<!--- Slideshow may not exist --->
34<cfif url.id is "" or not directoryExists(dir & "/" & url.id)>
35        <cfset direxists = false>
36<cfelse>
37        <cfset direxists = true>
38        <cfset metadata = application.slideshow.getInfo(dir & "/" & url.id)>
39        <cfset images = application.slideshow.getImages(dir & "/" & url.id)>
40        <cfparam name="form.formalname" default="#metadata.formalname#">
41</cfif>
42
43<!--- look for deletes --->
44<cfif isDefined("images")>
45        <cfloop query="images">
46                <cfif structKeyExists(form, "delete_#currentrow#")>
47                        <cfset toDelete = form["image_#currentRow#"]>
48                        <cffile action="delete" file="#dir#/#url.id#/#toDelete#">
49                        <!--- reget --->
50                        <cfset images = application.slideshow.getImages(dir & "/" & url.id)>
51                </cfif>         
52        </cfloop>
53</cfif>
54
55<cfif structKeyExists(form, "save")>
56        <cfset errors = arrayNew(1)>
57       
58        <cfif not len(trim(url.id))>
59                <cfset arrayAppend(errors, "The name cannot be blank.")>
60        <cfelse>
61                <cfset url.id = trim(url.id)>
62        </cfif>
63       
64        <cfif reFindNoCase("[^ [:alnum:]]", url.id)>
65                <cfset arrayAppend(errors, "The name must only contain letters, numbers, and spaces.")>
66        </cfif>
67
68        <cfif structKeyExists(form, "newimage") and len(trim(form.newimage))>
69                <cffile action="upload" filefield="form.newimage" destination="#dir#/#url.id#" nameconflict="makeunique">
70                <!--- reget --->
71                <cfset images = application.slideshow.getImages(dir & "/" & url.id)>           
72        </cfif>
73       
74        <cfif not arrayLen(errors)>
75                <!--- first, try to rename if needed --->
76                <cfif url.id neq form.oldname>
77                        <!--- new? --->
78                        <cfif form.oldname is "">
79                                <cfdirectory action="create" directory="#dir#/#url.id#">
80                                <!--- imediate reload --->
81                                <cflocation url="slideshow.cfm?id=#urlEncodedFormat(url.id)#" addToken="false">
82                        <cfelse>
83                                <cfdirectory action="rename" directory="#dir#/#form.oldname#" newdirectory="#dir#/#url.id#">
84                        </cfif>
85                </cfif>
86               
87                <!--- update metadata --->
88                <cfset metadata = structNew()>
89                <cfif len(trim(form.formalname))>
90                        <cfset metadata.formalname = trim(form.formalname)>
91                <cfelse>
92                        <cfset metadata.formalname = "">
93                </cfif>
94               
95                <cfset metadata.images = structNew()>
96                <cfset x = 1>
97                <cfloop condition="isDefined('form.image_#x#')">
98                        <cfif len(form["caption_#x#"])>
99                                <cfset metadata.images[form["image_#x#"]] = form["caption_#x#"]>
100                        </cfif>
101                        <cfset x = x + 1>
102                </cfloop>
103                <cfset application.slideshow.updateInfo(dir & "/" & url.id, metadata)>
104        </cfif>
105       
106</cfif>
107
108<cfmodule template="../tags/adminlayout.cfm" title="Slideshow Editor">
109
110        <cfoutput>
111        <script>
112        function showImage(url) {
113                cWin = window.open(url,"cWin","width=500,height=500,menubar=no,personalbar=no,dependent=true,directories=no,status=yes,toolbar=no,scrollbars=yes,resizable=yes");
114        }
115        </script>
116        </cfoutput>
117       
118        <cfif not direxists>
119                <cfoutput>
120                <p>
121                Please enter the name of of your new slideshow below. Once you have named the slide
122                show you will be able to enter more information and upload images. Please use just letters
123                and numbers with no spaces.
124                </p>
125                </cfoutput>
126        <cfelse>
127                <cfoutput>
128                <p>
129                Edit your slideshow below. If you rename the slideshow, please use just letter and numbers with
130                no spaces.
131                </p>
132                </cfoutput>
133        </cfif>
134       
135        <cfif structKeyExists(variables, "errors") and arrayLen(errors)>
136                <cfoutput>
137                <div class="errors">
138                Please correct the following error(s):
139                <ul>
140                <cfloop index="x" from="1" to="#arrayLen(errors)#">
141                <li>#errors[x]#</li>
142                </cfloop>
143                </ul>
144                </div>
145                </cfoutput>
146        </cfif>
147       
148        <cfoutput>
149        <form action="slideshow.cfm" method="post" enctype="multipart/form-data">
150        <input type="hidden" name="oldname" value="#url.id#">
151        <table>
152                <tr>
153                        <td align="right">name:</td>
154                        <td><input type="text" name="id" value="#url.id#" class="txtField" maxlength="50"></td>
155                </tr>
156                <cfif direxists>
157                <tr>
158                        <td align="right">descriptive name:</td>
159                        <td><input type="text" name="formalname" value="#form.formalname#" class="txtField" maxlength="50"></td>
160                </tr>
161                <cfif images.recordCount>
162                <tr>
163                        <td colspan="2">
164                        <p>
165                        Below are the images in the slide show. You may enter a caption for an image or delete it.
166                        Click on an image for a larger view.
167                        </p>
168                        </td>
169                </tr>
170                </cfif>
171                <cfloop query="images">
172                        <cfif structKeyExists(metadata.images, name)>
173                                <cfset value = metadata.images[name]>
174                        <cfelse>
175                                <cfset value = "">
176                        </cfif>
177                        <tr valign="middle" <cfif currentRow mod 2>bgcolor="##c0c0c0"</cfif>>
178                                <td align="right">#name#</td>
179                                <td>
180                                <a href="javaScript:showImage('#urlEncodedFormat("../images/slideshows/#application.imageroot#/#url.id#/#name#")#')"><img src="../images/slideshows/#application.imageroot#/#url.id#/#name#" width="50" height"50" align="absmiddle" border="0"></a>
181                                <input type="text" name="caption_#currentrow#" value="#value#" class="txtField">
182                                <input type="hidden" name="image_#currentrow#" value="#name#">
183                                <input type="submit" name="delete_#currentrow#" value="Delete">
184                                </td>
185                        </tr>
186                </cfloop>               
187                <tr>
188                        <td align="right">upload new image:</td>
189                        <td><input type="file" name="newimage"></td>
190                </tr>           
191                </cfif>
192                <tr>
193                        <td>&nbsp;</td>
194                        <td><input type="submit" name="cancel" value="Cancel"> <input type="submit" name="save" value="Save"></td>
195                </tr>
196        </table>
197        </form>
198        </cfoutput>
199</cfmodule>
200
201<cfsetting enablecfoutputonly=false>
Note: See TracBrowser for help on using the browser.