Search in sources :

Example 1 with HTMLWriter

use of web.HTMLWriter in project common by zenlunatics.

the class MailLists method writeSettingsInput.

// --------------------------------------------------------------------------
@Override
protected void writeSettingsInput(Field field, Map<String, Field> fields, Request request) throws IOException {
    super.writeSettingsInput(field, fields, request);
    if ("m_insert_headers".equals(field.getName())) {
        HTMLWriter writer = request.writer;
        writer.write("<div style=\"padding-left:20px\">");
        DBObject.writeInput(this, fields.get("m_header_before"), writer);
        writer.write("</div>");
    }
}
Also used : HTMLWriter(web.HTMLWriter)

Example 2 with HTMLWriter

use of web.HTMLWriter in project common by zenlunatics.

the class MailLists method writeLists.

// --------------------------------------------------------------------------
public void writeLists(Request request) throws IOException {
    Person user = request.getUser();
    int user_id = user.getId();
    Select query = new Select("mail_lists.id,mail_lists.name,mail_lists_people.mail_lists_id,mail_lists_digest.mail_lists_id").from("mail_lists LEFT JOIN mail_lists_people ON (mail_lists_people.mail_lists_id=mail_lists.id AND mail_lists_people.people_id=" + user_id + ") LEFT JOIN mail_lists_digest ON (mail_lists_digest.mail_lists_id=mail_lists.id AND mail_lists_digest.people_id=" + user_id + ")").where(request.testSessionFlag("show inactive lists") ? null : "mail_lists.active").orderBy("LOWER(mail_lists.name)");
    ResultSet rs = request.db.select(query);
    HTMLWriter writer = request.writer;
    writer.write("<table class=\"table table-hover\"><thead><tr><th>send email to list</th><th>archives</th><th>latest post</th><th>subscribed</th><th>nightly digest</th></tr></thead>");
    try {
        while (rs.next()) {
            int list_id = rs.getInt(1);
            String list = rs.getString(2);
            MailHandler mail_handler = getMailHandler(list, request.db);
            boolean subscribed = mail_handler != null ? mail_handler.isSubscribed(user, request) : rs.getString(3) != null;
            boolean archives_public = new MailList(list_id, request.site, request.db).archivesPublic();
            if (mail_handler != null && !archives_public && !subscribed)
                continue;
            writer.write("<tr class=\"lists\"><td>");
            String address = list + "@" + request.site.getSettings().getString("mail list domain");
            writer.a(m_show_full_address_on_email_page ? address : list, "mailto:" + address);
            writer.write("</td><td style=\"text-align:center\">");
            if (!archives_public && !subscribed)
                writer.setAttribute("style", "display:none");
            writer.setAttribute("id", "view" + list_id);
            writer.aButtonOnClick("view", "document.location=context+'/MailLists/" + list_id + "'");
            writer.write("</td><td>");
            if (!archives_public && !subscribed)
                writer.setAttribute("style", "display:none");
            writer.setAttribute("id", "date" + list_id);
            writer.tagOpen("span");
            writer.writeDate(request.db.lookupDate(new Select("max(arrived)").from("ml_" + list_id)));
            writer.tagClose();
            writer.write("</td><td style=\"text-align:center\">");
            if (mail_handler != null) {
                if (subscribed)
                    writer.write("&#10003;");
            } else {
                StringBuilder on_change = new StringBuilder("$('digest").append(list_id).append("').style.display=this.checked?'':'none';");
                if (!archives_public) {
                    on_change.append("$('view").append(list_id).append("').style.display=this.checked?'':'none';");
                    on_change.append("$('date").append(list_id).append("').style.display=this.checked?'':'none';");
                }
                on_change.append("toggle_subscription(this,").append(list_id).append(");return false");
                writer.setAttribute("onchange", on_change.toString());
                writer.checkbox(null, null, null, subscribed, true);
            }
            writer.write("</td><td style=\"text-align:center\">");
            writer.setAttribute("id", "digest" + list_id);
            writer.setAttribute("onchange", "toggle_digest(this," + list_id + ");return false");
            if (!subscribed)
                writer.setAttribute("style", "display:none");
            writer.checkbox(null, null, null, rs.getString(4) != null, true);
            writer.write("</td></tr>");
        }
        rs.getStatement().close();
    } catch (SQLException e) {
        request.abort(e);
    }
    writer.write("</table>");
}
Also used : HTMLWriter(web.HTMLWriter) SQLException(java.sql.SQLException) Select(db.Select) ResultSet(java.sql.ResultSet) Person(app.Person)

Example 3 with HTMLWriter

use of web.HTMLWriter in project common by zenlunatics.

the class MailLists method checkAll.

// --------------------------------------------------------------------------
@AdminTask
public void checkAll(Request request) throws IOException {
    HTMLWriter writer = request.writer;
    List<String[]> rows = request.db.readRows(new Select("host,username,password,id,name").from("mail_lists").where("active"));
    Session session = Session.getInstance(new Properties(), null);
    for (String[] row : rows) if (row.length == 5 && row[0] != null && row[2] != null)
        try {
            Store store = session.getStore(((MailLists) request.site.getModule("MailLists")).m_store_protocol);
            String account = accountName(row[1], Integer.parseInt(row[3]));
            writer.h4(row[4]);
            store.connect(row[0], account, row[2]);
            Folder folder = store.getFolder("INBOX");
            folder.open(Folder.READ_ONLY);
            Message[] messages = folder.getMessages();
            if (messages.length > 0) {
                writer.write("<table border=\"1\">");
                for (Message message : messages) {
                    writer.write("<tr><td>");
                    Date date = message.getReceivedDate();
                    if (date != null)
                        writer.write(date);
                    writer.write("</td><td>");
                    writer.write(message.getFrom()[0]);
                    writer.write("</td><td>");
                    writer.write(message.getSubject());
                    writer.write("</td><td>");
                    writer.write(message.getSize());
                    writer.write("</td></tr>");
                }
                writer.write("</table>");
            } else
                writer.write("0 messages");
            folder.close(false);
            store.close();
        } catch (MessagingException e) {
            writer.write(e.toString());
        } catch (IOException e) {
            writer.write(e.toString());
        }
}
Also used : HTMLWriter(web.HTMLWriter) Message(javax.mail.Message) MimeMessage(javax.mail.internet.MimeMessage) MessagingException(javax.mail.MessagingException) Store(javax.mail.Store) IOException(java.io.IOException) Properties(java.util.Properties) Folder(javax.mail.Folder) Date(java.util.Date) LocalDate(java.time.LocalDate) Select(db.Select) Session(javax.mail.Session) AdminTask(web.AdminTask)

Example 4 with HTMLWriter

use of web.HTMLWriter in project common by zenlunatics.

the class MailLists method writeMessage.

// --------------------------------------------------------------------------
private void writeMessage(String list, int message_id, Request request) throws IOException {
    HTMLWriter writer = request.writer;
    try {
        ResultSet rs = request.db.select(new Select("sender,arrived,message").from(list).whereIdEquals(message_id));
        if (rs.next()) {
            MailList mail_list = new MailList(Integer.parseInt(list.substring(3)), request.site, request.db);
            String text = mail_list.loadMessage(message_id, rs);
            if (text == null)
                writer.write("Message file not found.");
            else {
                String sender = rs.getString(1);
                writer.write("<div id=\"ml_message\">From: ").write(sender).write(" - ").write(DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(rs.getTimestamp(2))).br();
                if (m_show_reply_links_in_archives) {
                    writer.aButtonOnClick("reply to " + mail_list.getName(), "$('ml_message').replace(context+'/MailLists?list=" + list + "&cmd=reply_list&db_key_value=" + message_id + "');");
                    writer.space();
                    writer.aButtonOnClick("reply to " + sender, "$('ml_message').replace(context+'/MailLists?list=" + list + "&cmd=reply_sender&db_key_value=" + message_id + "');");
                }
                writer.hr();
                try {
                    InputStream is = new ByteArrayInputStream(text.getBytes());
                    MimeMessage message = new MimeMessage(getSession(), is);
                    Object content = message.getContent();
                    if (content instanceof String)
                        writer.write(content);
                    else
                        WebMail.writePart(message, message_id, (MimeMultipart) content, new ArrayList<Integer>(), writer);
                } catch (MessagingException e) {
                    sendError(list, "writeMessage", null, null, e);
                }
                writer.write("</div>");
            }
        } else
            writer.write("message not found");
        rs.getStatement().close();
    } catch (SQLException e) {
        sendError(list, "writeMessage", null, null, e);
    }
}
Also used : HTMLWriter(web.HTMLWriter) MessagingException(javax.mail.MessagingException) SQLException(java.sql.SQLException) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) ByteArrayInputStream(java.io.ByteArrayInputStream) MimeMessage(javax.mail.internet.MimeMessage) MimeMultipart(javax.mail.internet.MimeMultipart) ResultSet(java.sql.ResultSet) Select(db.Select) DBObject(db.DBObject)

Example 5 with HTMLWriter

use of web.HTMLWriter in project common by zenlunatics.

the class MailLists method writeArchiveViewer.

// --------------------------------------------------------------------------
private void writeArchiveViewer(int list_id, Request request) throws IOException {
    MailList mail_list = new MailList(list_id, request.site, request.db);
    if (mail_list.getId() == 0)
        request.abort("writeArchiveViewer: list " + list_id + " not found");
    HTMLWriter writer = request.writer;
    writer.write("<h3>").write(mail_list.getName()).write(" mail list archive</h3>");
    writer.write("<table><tr><td style=\"padding:0 10px;vertical-align:top;width:200px;\">");
    ResultSet rs = request.db.select("SELECT DISTINCT extract(month from arrived) m,extract(year from arrived) y FROM ml_" + list_id + " ORDER BY y DESC,m");
    try {
        if (rs.next()) {
            writer.write("<div class=\"list_border_outer\"><div class=\"list_border_inner\">");
            Accordion accordion = new Accordion(writer).setActiveGroup(0).open();
            NavList nav_list = new NavList(writer);
            String[] months = new String[] { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
            int year = 0;
            int most_recent_month = -1;
            int most_recent_year = rs.getInt(2);
            int month = 0;
            do {
                if (year != rs.getInt(2)) {
                    if (most_recent_month == -1)
                        most_recent_month = 0;
                    else if (most_recent_month == 0)
                        most_recent_month = month;
                    nav_list.close();
                    year = rs.getInt(2);
                    accordion.heading(Integer.toString(year));
                    nav_list.open();
                }
                month = rs.getInt(1);
                nav_list.aOnClick(months[rs.getInt(1) - 1], "$('ml_headers').replace(context+'/MailLists/" + mail_list.getId() + "/headers/" + year + "/" + month + "');");
            } while (rs.next());
            if (most_recent_month <= 0)
                most_recent_month = month;
            nav_list.close();
            accordion.close();
            writer.write("</div></div>");
            writer.write("<div class=\"well\" style=\"margin:10px 0;\"><form id=\"search\">");
            writer.write("Search for:");
            writer.setAttribute("onfocus", "$('options').style.display='block'");
            writer.setAttribute("onkeypress", "if(event.keyCode==13){$('go_btn').click();return false;}");
            writer.textInput("search", null, null);
            writer.write("<div id=\"options\" style=\"display:none;\">show emails containing:");
            writer.setAttribute("id", "all");
            writer.radioButton("words", "all search words", "all", true, null);
            writer.radioButton("words", "any search word", "any", false, null);
            writer.setAttribute("id", "subject");
            writer.checkbox("subject", "search subject", null, true, false);
            writer.setAttribute("id", "message");
            writer.checkbox("message", "search message (slow)", null, false, false);
            writer.write("</div>");
            writer.setAttribute("id", "go_btn");
            writer.aButtonOnClick("go", "var m=$('ml_headers');m.set('html','searching...');m.replace(context+'/MailLists/" + list_id + "/search?'+$('search').toQueryString());");
            writer.write("</form></div>");
            writer.scriptOpen().write("window.addEvent('load',function(){$('ml_headers').replace(context+'/MailLists/").write(list_id).write("/headers/").write(most_recent_year).write("/").write(most_recent_month).write("');});").scriptClose();
        } else
            writer.write("empty archives");
        rs.getStatement().close();
    } catch (SQLException e) {
        request.abort(e);
    }
    writer.write("<div id=\"subscribers\"><div class=\"list_border_outer\"><div class=\"list_border_inner\">");
    NavList nav_list = new NavList(writer).addStyle("font-size", "12px").addStyle("white-space", "nowrap");
    nav_list.open();
    MailHandler mail_handler = getMailHandler(mail_list.getName(), request.db);
    if (mail_handler != null)
        mail_handler.writeSubscribers(nav_list, request.site, request.db);
    else
        mail_list.writeSubscribers(nav_list, request.site, request.db);
    nav_list.close();
    writer.write("</div></div>");
    writer.write("</div></td><td valign=\"top\" style=\"height:200px;padding:0 10px 10px 0;\"><div id=\"ml_headers\" class=\"mail_archive_headers\"></td></tr></table>");
}
Also used : HTMLWriter(web.HTMLWriter) Accordion(web.Accordion) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) NavList(web.NavList)

Aggregations

HTMLWriter (web.HTMLWriter)109 Select (db.Select)18 SQLException (java.sql.SQLException)16 ResultSet (java.sql.ResultSet)14 Table (web.Table)12 JDBCTable (db.JDBCTable)10 Person (app.Person)7 Calendar (java.util.Calendar)7 ArrayList (java.util.ArrayList)6 JDBCColumn (db.JDBCColumn)5 View (db.View)5 DBObject (db.DBObject)4 Form (db.Form)4 File (java.io.File)4 AdminTask (web.AdminTask)4 FilePathStringBuilder (web.FilePathStringBuilder)4 Select (web.Select)4 Mode (db.View.Mode)3 IOException (java.io.IOException)3 NumberFormat (java.text.NumberFormat)3