Search in sources :

Example 1 with QuotaLimit

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);
    }
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) QuotaLimit(net.jforum.entities.QuotaLimit) DatabaseException(net.jforum.exceptions.DatabaseException)

Example 2 with QuotaLimit

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;
}
Also used : QuotaLimit(net.jforum.entities.QuotaLimit)

Example 3 with QuotaLimit

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();
}
Also used : AttachmentDAO(net.jforum.dao.AttachmentDAO) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) QuotaLimit(net.jforum.entities.QuotaLimit)

Example 4 with 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);
}
Also used : PollDAO(net.jforum.dao.PollDAO) User(net.jforum.entities.User) PostDAO(net.jforum.dao.PostDAO) UserDAO(net.jforum.dao.UserDAO) Poll(net.jforum.entities.Poll) Topic(net.jforum.entities.Topic) QuotaLimit(net.jforum.entities.QuotaLimit) AttachmentCommon(net.jforum.view.forum.common.AttachmentCommon)

Example 5 with QuotaLimit

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;
}
Also used : User(net.jforum.entities.User) Iterator(java.util.Iterator) QuotaLimit(net.jforum.entities.QuotaLimit)

Aggregations

QuotaLimit (net.jforum.entities.QuotaLimit)9 User (net.jforum.entities.User)4 Topic (net.jforum.entities.Topic)3 AttachmentCommon (net.jforum.view.forum.common.AttachmentCommon)3 PostDAO (net.jforum.dao.PostDAO)2 UserDAO (net.jforum.dao.UserDAO)2 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 AttachmentDAO (net.jforum.dao.AttachmentDAO)1 PollDAO (net.jforum.dao.PollDAO)1 Attachment (net.jforum.entities.Attachment)1 AttachmentExtension (net.jforum.entities.AttachmentExtension)1 AttachmentInfo (net.jforum.entities.AttachmentInfo)1 Forum (net.jforum.entities.Forum)1