001: /*
002: * Copyright (c) JForum Team
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms,
006: * with or without modification, are permitted provided
007: * that the following conditions are met:
008: *
009: * 1) Redistributions of source code must retain the above
010: * copyright notice, this list of conditions and the
011: * following disclaimer.
012: * 2) Redistributions in binary form must reproduce the
013: * above copyright notice, this list of conditions and
014: * the following disclaimer in the documentation and/or
015: * other materials provided with the distribution.
016: * 3) Neither the name of "Rafael Steil" nor
017: * the names of its contributors may be used to endorse
018: * or promote products derived from this software without
019: * specific prior written permission.
020: *
021: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
022: * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
023: * EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
024: * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
025: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR
026: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
027: * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
028: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
029: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES
030: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
031: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
032: * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
033: * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
034: * IN CONTRACT, STRICT LIABILITY, OR TORT
035: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
036: * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
037: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
038: *
039: * Created on Jan 17, 2005 2:46:30 PM
040: * The JForum Project
041: * http://www.jforum.net
042: */
043: package net.jforum.view.admin;
044:
045: import java.util.ArrayList;
046: import java.util.Arrays;
047: import java.util.List;
048:
049: import net.jforum.dao.AttachmentDAO;
050: import net.jforum.dao.DataAccessDriver;
051: import net.jforum.entities.AttachmentExtension;
052: import net.jforum.entities.AttachmentExtensionGroup;
053: import net.jforum.entities.QuotaLimit;
054: import net.jforum.util.TreeGroup;
055: import net.jforum.util.preferences.ConfigKeys;
056: import net.jforum.util.preferences.SystemGlobals;
057: import net.jforum.util.preferences.TemplateKeys;
058:
059: /**
060: * @author Rafael Steil
061: * @version $Id: AttachmentsAction.java,v 1.16 2006/08/20 22:47:45 rafaelsteil Exp $
062: */
063: public class AttachmentsAction extends AdminCommand {
064: public void configurations() {
065: this .context.put("icon", SystemGlobals
066: .getValue(ConfigKeys.ATTACHMENTS_ICON));
067: this .context
068: .put(
069: "createThumb",
070: SystemGlobals
071: .getBoolValue(ConfigKeys.ATTACHMENTS_IMAGES_CREATE_THUMB));
072: this .context.put("thumbH", SystemGlobals
073: .getValue(ConfigKeys.ATTACHMENTS_IMAGES_MAX_THUMB_H));
074: this .context.put("thumbW", SystemGlobals
075: .getValue(ConfigKeys.ATTACHMENTS_IMAGES_MAX_THUMB_W));
076: this .context.put("maxPost", SystemGlobals
077: .getValue(ConfigKeys.ATTACHMENTS_MAX_POST));
078: this .context
079: .put(
080: "thumbBorder",
081: SystemGlobals
082: .getBoolValue(ConfigKeys.ATTACHMENTS_IMAGES_THUMB_BOX_SHOW));
083:
084: this .setTemplateName(TemplateKeys.ATTACHMENTS_CONFIG);
085: }
086:
087: public void configurationsSave() {
088: ConfigAction ca = new ConfigAction(this .request, this .response,
089: this .context);
090: ca.updateData(ca.getConfig());
091:
092: this .configurations();
093: }
094:
095: public void quotaLimit() {
096: AttachmentDAO am = DataAccessDriver.getInstance()
097: .newAttachmentDAO();
098:
099: this .context.put("quotas", am.selectQuotaLimit());
100: this .setTemplateName(TemplateKeys.ATTACHMENTS_QUOTA_LIMIT);
101: this .context.put("groups", new TreeGroup().getNodes());
102: this .context.put("selectedList", new ArrayList());
103: this .context.put("groupQuotas", am.selectGroupsQuotaLimits());
104: }
105:
106: public void quotaLimitSave() {
107: QuotaLimit ql = new QuotaLimit();
108: ql.setDescription(this .request
109: .getParameter("quota_description"));
110: ql.setSize(this .request.getIntParameter("max_filesize"));
111: ql.setType(this .request.getIntParameter("type"));
112:
113: DataAccessDriver.getInstance().newAttachmentDAO()
114: .addQuotaLimit(ql);
115: this .quotaLimit();
116: }
117:
118: public void quotaLimitUpdate() {
119: AttachmentDAO am = DataAccessDriver.getInstance()
120: .newAttachmentDAO();
121:
122: // First check if we should delete some entry
123: String[] delete = this .request.getParameterValues("delete");
124: List deleteList = new ArrayList();
125: if (delete != null) {
126: deleteList = Arrays.asList(delete);
127: am.removeQuotaLimit(delete);
128: }
129:
130: // Now update the remaining
131: int total = this .request.getIntParameter("total_records");
132: for (int i = 0; i < total; i++) {
133: if (deleteList.contains(this .request
134: .getParameter("id_" + i))) {
135: continue;
136: }
137:
138: QuotaLimit ql = new QuotaLimit();
139: ql.setId(this .request.getIntParameter("id_" + i));
140: ql.setDescription(this .request.getParameter("quota_desc_"
141: + i));
142: ql.setSize(this .request
143: .getIntParameter("max_filesize_" + i));
144: ql.setType(this .request.getIntParameter("type_" + i));
145:
146: am.updateQuotaLimit(ql);
147: }
148:
149: this .quotaLimit();
150: }
151:
152: public void extensionGroups() {
153: this .setTemplateName(TemplateKeys.ATTACHMENTS_EXTENSION_GROUPS);
154: this .context.put("groups", DataAccessDriver.getInstance()
155: .newAttachmentDAO().selectExtensionGroups());
156: }
157:
158: public void extensionGroupsSave() {
159: AttachmentExtensionGroup g = new AttachmentExtensionGroup();
160: g.setAllow(this .request.getParameter("allow") != null);
161: g
162: .setDownloadMode(this .request
163: .getIntParameter("download_mode"));
164: g.setName(this .request.getParameter("name"));
165: g.setUploadIcon(this .request.getParameter("upload_icon"));
166:
167: DataAccessDriver.getInstance().newAttachmentDAO()
168: .addExtensionGroup(g);
169: this .extensionGroups();
170: }
171:
172: public void extensionGroupsUpdate() {
173: AttachmentDAO am = DataAccessDriver.getInstance()
174: .newAttachmentDAO();
175:
176: // Check if there are records to remove
177: String[] delete = this .request.getParameterValues("delete");
178: List deleteList = new ArrayList();
179: if (delete != null) {
180: deleteList = Arrays.asList(delete);
181: am.removeExtensionGroups(delete);
182: }
183:
184: // Update
185: int total = this .request.getIntParameter("total_records");
186: for (int i = 0; i < total; i++) {
187: if (deleteList.contains(this .request
188: .getParameter("id_" + i))) {
189: continue;
190: }
191:
192: AttachmentExtensionGroup g = new AttachmentExtensionGroup();
193: g.setId(this .request.getIntParameter("id_" + i));
194: g.setAllow(this .request.getParameter("allow_" + i) != null);
195: g.setDownloadMode(this .request
196: .getIntParameter("download_mode_" + i));
197: g.setName(this .request.getParameter("name_" + i));
198: g.setUploadIcon(this .request.getParameter("upload_icon_"
199: + i));
200:
201: am.updateExtensionGroup(g);
202: }
203:
204: this .extensionGroups();
205: }
206:
207: public void extensions() {
208: AttachmentDAO am = DataAccessDriver.getInstance()
209: .newAttachmentDAO();
210:
211: this .setTemplateName(TemplateKeys.ATTACHMENTS_EXTENSIONS);
212: this .context.put("extensions", am.selectExtensions());
213: this .context.put("groups", am.selectExtensionGroups());
214: }
215:
216: public void extensionsSave() {
217: AttachmentExtension e = new AttachmentExtension();
218: e.setAllow(this .request.getParameter("allow") != null);
219: e.setComment(this .request.getParameter("comment"));
220: e.setExtension(this .request.getParameter("extension"));
221: e.setUploadIcon(this .request.getParameter("upload_icon"));
222: e.setExtensionGroupId(this .request
223: .getIntParameter("extension_group"));
224:
225: if (e.getExtension().startsWith(".")) {
226: e.setExtension(e.getExtension().substring(1));
227: }
228:
229: DataAccessDriver.getInstance().newAttachmentDAO().addExtension(
230: e);
231: this .extensions();
232: }
233:
234: public void extensionsUpdate() {
235: AttachmentDAO am = DataAccessDriver.getInstance()
236: .newAttachmentDAO();
237:
238: // Check for records to delete
239: String[] delete = this .request.getParameterValues("delete");
240: List deleteList = new ArrayList();
241:
242: if (delete != null) {
243: deleteList = Arrays.asList(delete);
244: am.removeExtensions(delete);
245: }
246:
247: int total = this .request.getIntParameter("total_records");
248:
249: for (int i = 0; i < total; i++) {
250: if (deleteList.contains(this .request
251: .getParameter("id_" + i))) {
252: continue;
253: }
254:
255: AttachmentExtension e = new AttachmentExtension();
256: e.setAllow(this .request.getParameter("allow_" + i) != null);
257: e.setComment(this .request.getParameter("comment_" + i));
258: e.setExtension(this .request.getParameter("extension_" + i));
259: e.setExtensionGroupId(this .request
260: .getIntParameter("extension_group_" + i));
261: e.setId(this .request.getIntParameter("id_" + i));
262: e.setUploadIcon(this .request.getParameter("upload_icon_"
263: + i));
264:
265: am.updateExtension(e);
266: }
267:
268: this .extensions();
269: }
270:
271: public void quotaGroupsSave() {
272: int total = this .request.getIntParameter("total_groups");
273: AttachmentDAO am = DataAccessDriver.getInstance()
274: .newAttachmentDAO();
275: am.cleanGroupQuota();
276:
277: for (int i = 0; i < total; i++) {
278: String l = this .request.getParameter("limit_" + i);
279:
280: if (l == null || l.equals("")) {
281: continue;
282: }
283:
284: int limitId = Integer.parseInt(l);
285: int groupId = this .request.getIntParameter("group_" + i);
286:
287: if (groupId > 0) {
288: am.setGroupQuota(groupId, limitId);
289: }
290: }
291:
292: this .quotaLimit();
293: }
294:
295: /**
296: * @see net.jforum.Command#list()
297: */
298: public void list() {
299: this.configurations();
300: }
301: }
|