1 43 package net.jforum.view.admin; 44 45 import java.util.ArrayList ; 46 import java.util.Arrays ; 47 import java.util.List ; 48 49 import net.jforum.dao.AttachmentDAO; 50 import net.jforum.dao.DataAccessDriver; 51 import net.jforum.entities.AttachmentExtension; 52 import net.jforum.entities.AttachmentExtensionGroup; 53 import net.jforum.entities.QuotaLimit; 54 import net.jforum.util.TreeGroup; 55 import net.jforum.util.preferences.ConfigKeys; 56 import net.jforum.util.preferences.SystemGlobals; 57 import net.jforum.util.preferences.TemplateKeys; 58 59 63 public class AttachmentsAction extends AdminCommand 64 { 65 public void configurations() throws Exception 66 { 67 this.context.put("icon", SystemGlobals.getValue(ConfigKeys.ATTACHMENTS_ICON)); 68 this.context.put("createThumb", SystemGlobals.getBoolValue(ConfigKeys.ATTACHMENTS_IMAGES_CREATE_THUMB)); 69 this.context.put("thumbH", SystemGlobals.getValue(ConfigKeys.ATTACHMENTS_IMAGES_MAX_THUMB_H)); 70 this.context.put("thumbW", SystemGlobals.getValue(ConfigKeys.ATTACHMENTS_IMAGES_MAX_THUMB_W)); 71 this.context.put("maxPost", SystemGlobals.getValue(ConfigKeys.ATTACHMENTS_MAX_POST)); 72 this.context.put("thumbBorder", SystemGlobals.getBoolValue(ConfigKeys.ATTACHMENTS_IMAGES_THUMB_BOX_SHOW)); 73 74 this.setTemplateName(TemplateKeys.ATTACHMENTS_CONFIG); 75 } 76 77 public void configurationsSave() throws Exception 78 { 79 ConfigAction ca = new ConfigAction(this.request, this.response, this.context); 80 ca.updateData(ca.getConfig()); 81 82 this.configurations(); 83 } 84 85 public void quotaLimit() throws Exception 86 { 87 AttachmentDAO am = DataAccessDriver.getInstance().newAttachmentDAO(); 88 89 this.context.put("quotas", am.selectQuotaLimit()); 90 this.setTemplateName(TemplateKeys.ATTACHMENTS_QUOTA_LIMIT); 91 this.context.put("groups", new TreeGroup().getNodes()); 92 this.context.put("selectedList", new ArrayList ()); 93 this.context.put("groupQuotas", am.selectGroupsQuotaLimits()); 94 } 95 96 public void quotaLimitSave() throws Exception 97 { 98 QuotaLimit ql = new QuotaLimit(); 99 ql.setDescription(this.request.getParameter("quota_description")); 100 ql.setSize(this.request.getIntParameter("max_filesize")); 101 ql.setType(this.request.getIntParameter("type")); 102 103 DataAccessDriver.getInstance().newAttachmentDAO().addQuotaLimit(ql); 104 this.quotaLimit(); 105 } 106 107 public void quotaLimitUpdate() throws Exception 108 { 109 AttachmentDAO am = DataAccessDriver.getInstance().newAttachmentDAO(); 110 111 String [] delete = this.request.getParameterValues("delete"); 113 List deleteList = new ArrayList (); 114 if (delete != null) { 115 deleteList = Arrays.asList(delete); 116 am.removeQuotaLimit(delete); 117 } 118 119 int total = this.request.getIntParameter("total_records"); 121 for (int i = 0; i < total; i++) { 122 if (deleteList.contains(this.request.getParameter("id_" + i))) { 123 continue; 124 } 125 126 QuotaLimit ql = new QuotaLimit(); 127 ql.setId(this.request.getIntParameter("id_" + i)); 128 ql.setDescription(this.request.getParameter("quota_desc_" + i)); 129 ql.setSize(this.request.getIntParameter("max_filesize_" + i)); 130 ql.setType(this.request.getIntParameter("type_" + i)); 131 132 am.updateQuotaLimit(ql); 133 } 134 135 this.quotaLimit(); 136 } 137 138 public void extensionGroups() throws Exception 139 { 140 this.setTemplateName(TemplateKeys.ATTACHMENTS_EXTENSION_GROUPS); 141 this.context.put("groups", DataAccessDriver.getInstance().newAttachmentDAO().selectExtensionGroups()); 142 } 143 144 public void extensionGroupsSave() throws Exception 145 { 146 AttachmentExtensionGroup g = new AttachmentExtensionGroup(); 147 g.setAllow(this.request.getParameter("allow") != null); 148 g.setDownloadMode(this.request.getIntParameter("download_mode")); 149 g.setName(this.request.getParameter("name")); 150 g.setUploadIcon(this.request.getParameter("upload_icon")); 151 152 DataAccessDriver.getInstance().newAttachmentDAO().addExtensionGroup(g); 153 this.extensionGroups(); 154 } 155 156 public void extensionGroupsUpdate() throws Exception 157 { 158 AttachmentDAO am = DataAccessDriver.getInstance().newAttachmentDAO(); 159 160 String [] delete = this.request.getParameterValues("delete"); 162 List deleteList = new ArrayList (); 163 if (delete != null) { 164 deleteList = Arrays.asList(delete); 165 am.removeExtensionGroups(delete); 166 } 167 168 int total = this.request.getIntParameter("total_records"); 170 for (int i = 0; i < total; i++) { 171 if (deleteList.contains(this.request.getParameter("id_" + i))) { 172 continue; 173 } 174 175 AttachmentExtensionGroup g = new AttachmentExtensionGroup(); 176 g.setId(this.request.getIntParameter("id_" + i)); 177 g.setAllow(this.request.getParameter("allow_" + i) != null); 178 g.setDownloadMode(this.request.getIntParameter("download_mode_" + i)); 179 g.setName(this.request.getParameter("name_" + i)); 180 g.setUploadIcon(this.request.getParameter("upload_icon_" + i)); 181 182 am.updateExtensionGroup(g); 183 } 184 185 this.extensionGroups(); 186 } 187 188 public void extensions() throws Exception 189 { 190 AttachmentDAO am = DataAccessDriver.getInstance().newAttachmentDAO(); 191 192 this.setTemplateName(TemplateKeys.ATTACHMENTS_EXTENSIONS); 193 this.context.put("extensions", am.selectExtensions()); 194 this.context.put("groups", am.selectExtensionGroups()); 195 } 196 197 public void extensionsSave() throws Exception 198 { 199 AttachmentExtension e = new AttachmentExtension(); 200 e.setAllow(this.request.getParameter("allow") != null); 201 e.setComment(this.request.getParameter("comment")); 202 e.setExtension(this.request.getParameter("extension")); 203 e.setUploadIcon(this.request.getParameter("upload_icon")); 204 e.setExtensionGroupId(this.request.getIntParameter("extension_group")); 205 206 if (e.getExtension().startsWith(".")) { 207 e.setExtension(e.getExtension().substring(1)); 208 } 209 210 DataAccessDriver.getInstance().newAttachmentDAO().addExtension(e); 211 this.extensions(); 212 } 213 214 public void extensionsUpdate() throws Exception 215 { 216 AttachmentDAO am = DataAccessDriver.getInstance().newAttachmentDAO(); 217 218 String [] delete = this.request.getParameterValues("delete"); 220 List deleteList = new ArrayList (); 221 if (delete != null) { 222 deleteList = Arrays.asList(delete); 223 am.removeExtensions(delete); 224 } 225 226 int total = this.request.getIntParameter("total_records"); 227 for (int i = 0; i < total; i++) { 228 if (deleteList.contains(this.request.getParameter("id_" + i))) { 229 continue; 230 } 231 232 AttachmentExtension e = new AttachmentExtension(); 233 e.setAllow(this.request.getParameter("allow_" + i) != null); 234 e.setComment(this.request.getParameter("comment_" + i)); 235 e.setExtension(this.request.getParameter("extension_" + i)); 236 e.setExtensionGroupId(this.request.getIntParameter("extension_group_" + i)); 237 e.setId(this.request.getIntParameter("id_" + i)); 238 e.setUploadIcon(this.request.getParameter("upload_icon_" + i)); 239 240 am.updateExtension(e); 241 } 242 243 this.extensions(); 244 } 245 246 public void quotaGroupsSave() throws Exception 247 { 248 int total = this.request.getIntParameter("total_groups"); 249 AttachmentDAO am = DataAccessDriver.getInstance().newAttachmentDAO(); 250 am.cleanGroupQuota(); 251 252 for (int i = 0; i < total; i++) { 253 String l = this.request.getParameter("limit_" + i); 254 if (l == null || l.equals("")) { 255 continue; 256 } 257 258 int limitId = Integer.parseInt(l); 259 int groupId = this.request.getIntParameter("group_" + i); 260 261 if (groupId > 0) { 262 am.setGroupQuota(groupId, limitId); 263 } 264 } 265 266 this.quotaLimit(); 267 } 268 269 272 public void list() throws Exception 273 { 274 this.configurations(); 275 } 276 } 277 | Popular Tags |