use of net.jforum.entities.QuotaLimit in project jforum2 by rafaelsteil.
the class GenericAttachmentDAO method selectQuotaLimitByGroup.
/**
* @see net.jforum.dao.AttachmentDAO#selectQuotaLimit()
*/
public QuotaLimit selectQuotaLimitByGroup(int groupId) {
QuotaLimit ql = null;
PreparedStatement p = null;
ResultSet rs = null;
try {
p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("AttachmentModel.selectQuotaLimitByGroup"));
p.setInt(1, groupId);
rs = p.executeQuery();
if (rs.next()) {
ql = this.getQuotaLimit(rs);
}
return ql;
} catch (SQLException e) {
throw new DatabaseException(e);
} finally {
DbUtils.close(rs, p);
}
}
use of net.jforum.entities.QuotaLimit in project jforum2 by rafaelsteil.
the class GenericAttachmentDAO method getQuotaLimit.
protected QuotaLimit getQuotaLimit(ResultSet rs) throws SQLException {
QuotaLimit ql = new QuotaLimit();
ql.setDescription(rs.getString("quota_desc"));
ql.setId(rs.getInt("quota_limit_id"));
ql.setSize(rs.getInt("quota_limit"));
ql.setType(rs.getInt("quota_type"));
return ql;
}
use of net.jforum.entities.QuotaLimit in project jforum2 by rafaelsteil.
the class AttachmentsAction method quotaLimitUpdate.
public void quotaLimitUpdate() {
AttachmentDAO am = DataAccessDriver.getInstance().newAttachmentDAO();
// First check if we should delete some entry
String[] delete = this.request.getParameterValues("delete");
List deleteList = new ArrayList();
if (delete != null) {
deleteList = Arrays.asList(delete);
am.removeQuotaLimit(delete);
}
// Now update the remaining
int total = this.request.getIntParameter("total_records");
for (int i = 0; i < total; i++) {
if (deleteList.contains(this.request.getParameter("id_" + i))) {
continue;
}
QuotaLimit ql = new QuotaLimit();
ql.setId(this.request.getIntParameter("id_" + i));
ql.setDescription(this.request.getParameter("quota_desc_" + i));
ql.setSize(this.request.getIntParameter("max_filesize_" + i));
ql.setType(this.request.getIntParameter("type_" + i));
am.updateQuotaLimit(ql);
}
this.quotaLimit();
}
use of net.jforum.entities.QuotaLimit in project jforum2 by rafaelsteil.
the class PostAction method edit.
private void edit(boolean preview, Post p) {
int userId = SessionFacade.getUserSession().getUserId();
if (!preview) {
PostDAO pm = DataAccessDriver.getInstance().newPostDAO();
p = pm.selectById(this.request.getIntParameter("post_id"));
// The post exist?
if (p.getId() == 0) {
this.postNotFound();
return;
}
}
boolean isModerator = SecurityRepository.canAccess(SecurityConstants.PERM_MODERATION_POST_EDIT);
boolean canEdit = SessionFacade.isLogged() && (isModerator || p.getUserId() == userId);
if (!canEdit) {
this.setTemplateName(TemplateKeys.POSTS_EDIT_CANNOTEDIT);
this.context.put("message", I18n.getMessage("CannotEditPost"));
} else {
Topic topic = TopicRepository.getTopic(new Topic(p.getTopicId()));
if (topic == null) {
topic = DataAccessDriver.getInstance().newTopicDAO().selectRaw(p.getTopicId());
}
if (!TopicsCommon.isTopicAccessible(topic.getForumId())) {
return;
}
if (topic.getStatus() == Topic.STATUS_LOCKED && !isModerator) {
this.topicLocked();
return;
}
if (preview && this.request.getParameter("topic_type") != null) {
topic.setType(this.request.getIntParameter("topic_type"));
}
if (p.hasAttachments()) {
this.context.put("attachments", DataAccessDriver.getInstance().newAttachmentDAO().selectAttachments(p.getId()));
}
Poll poll = null;
if (topic.isVote() && topic.getFirstPostId() == p.getId()) {
// It has a poll associated with the topic
PollDAO poolDao = DataAccessDriver.getInstance().newPollDAO();
poll = poolDao.selectById(topic.getVoteId());
}
this.setTemplateName(TemplateKeys.POSTS_EDIT);
this.context.put("attachmentsEnabled", SecurityRepository.canAccess(SecurityConstants.PERM_ATTACHMENTS_ENABLED, Integer.toString(p.getForumId())));
this.context.put("moderationLoggingEnabled", SystemGlobals.getBoolValue(ConfigKeys.MODERATION_LOGGING_ENABLED));
QuotaLimit ql = new AttachmentCommon(this.request, p.getForumId()).getQuotaLimit(userId);
this.context.put("maxAttachmentsSize", new Long(ql != null ? ql.getSizeInBytes() : 1));
this.context.put("isEdit", true);
this.context.put("maxAttachments", SystemGlobals.getValue(ConfigKeys.ATTACHMENTS_MAX_POST));
this.context.put("smilies", SmiliesRepository.getSmilies());
this.context.put("forum", ForumRepository.getForum(p.getForumId()));
this.context.put("action", "editSave");
this.context.put("post", p);
this.context.put("setType", p.getId() == topic.getFirstPostId());
this.context.put("topic", topic);
this.context.put("poll", poll);
this.context.put("pageTitle", I18n.getMessage("PostShow.messageTitle") + " " + p.getSubject());
this.context.put("isModerator", isModerator);
this.context.put("start", this.request.getParameter("start"));
this.context.put("htmlAllowed", SecurityRepository.canAccess(SecurityConstants.PERM_HTML_DISABLED, Integer.toString(topic.getForumId())));
this.context.put("canCreateStickyOrAnnouncementTopics", SecurityRepository.canAccess(SecurityConstants.PERM_CREATE_STICKY_ANNOUNCEMENT_TOPICS));
this.context.put("canCreatePolls", SecurityRepository.canAccess(SecurityConstants.PERM_CREATE_POLL));
}
UserDAO udao = DataAccessDriver.getInstance().newUserDAO();
User u = udao.selectById(userId);
ViewCommon.prepareUserSignature(u);
if (preview) {
u.setNotifyOnMessagesEnabled(this.request.getParameter("notify") != null);
if (u.getId() != p.getUserId()) {
// Probably a moderator is editing the message
User previewUser = udao.selectById(p.getUserId());
ViewCommon.prepareUserSignature(previewUser);
this.context.put("previewUser", previewUser);
}
}
this.context.put("user", u);
}
use of net.jforum.entities.QuotaLimit in project jforum2 by rafaelsteil.
the class AttachmentCommon method getQuotaLimit.
public QuotaLimit getQuotaLimit(int userId) {
QuotaLimit ql = new QuotaLimit();
User u = DataAccessDriver.getInstance().newUserDAO().selectById(userId);
for (Iterator iter = u.getGroupsList().iterator(); iter.hasNext(); ) {
QuotaLimit l = this.am.selectQuotaLimitByGroup(((Group) iter.next()).getId());
if (l == null) {
continue;
}
if (l.getSizeInBytes() > ql.getSizeInBytes()) {
ql = l;
}
}
if (ql.getSize() == 0) {
return null;
}
return ql;
}
Aggregations