Search in sources :

Example 6 with Select

use of db.Select in project common by zenlunatics.

the class Design method write.

// --------------------------------------------------------------------------
public void write(Page page, Request request) throws IOException {
    getHead(request).close();
    HTMLWriter writer = request.writer;
    ResultSet rs = request.db.select(new Select("*").from("designs_items").where("designs_id=" + m_id).orderBy("_order_"));
    try {
        while (rs.next()) {
            String type = rs.getString("type");
            if ("html".equals(type))
                writer.write(rs.getString("data"));
            else if ("page".equals(type))
                page.write(request);
        }
    } catch (SQLException e) {
    } finally {
        try {
            rs.getStatement().close();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
    request.close();
}
Also used : HTMLWriter(web.HTMLWriter) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) Select(db.Select)

Example 7 with Select

use of db.Select in project common by zenlunatics.

the class People method writeRolesPane.

// --------------------------------------------------------------------
@SuppressWarnings("unchecked")
private void writeRolesPane(Request request) throws IOException {
    HTMLWriter writer = request.writer;
    writer.setAttribute("style", "margin-bottom:20px;");
    writer.aButtonOnClick("add", "dialog_prompt('Role',function(r){XHR_post(context+'/People/Roles/'+r+'/add',null,function(){$('EditSite').replace()})},{title:'Add Role'})");
    List<SelectOption> roles = (List<SelectOption>) request.site.getObjects("_roles_").getObjects();
    for (SelectOption role : roles) {
        String text = role.getText();
        writer.write("<div class=\"panel panel-default\"><div class=\"panel-heading\" style=\"display:flex;justify-content:space-between\">");
        writer.write(text);
        if (!"admin".equals(text) && !"coho".equals(text))
            writer.aButtonOnClick("delete", "dialog_confirm('Delete " + text + " role?' ,function(){XHR_post(context+'/People/Roles/" + text + "/delete',null,function(){$('EditSite').replace()})})");
        writer.write("</div><div class=\"panel-body\">");
        List<String> people = request.db.readValues(new Select("first || ' ' || last").from("people").join("people", "user_roles").where("role='" + text + "'"));
        writer.write(Util.join(", ", people));
        writer.write("</div></div>");
    }
}
Also used : HTMLWriter(web.HTMLWriter) SelectOption(web.SelectOption) Select(db.Select) ArrayList(java.util.ArrayList) List(java.util.List)

Example 8 with Select

use of db.Select in project common by zenlunatics.

the class Site method mailPassword.

// --------------------------------------------------------------------------
public boolean mailPassword(String user_name, Request request) {
    if (user_name == null)
        return false;
    int id = request.db.lookupInt(new Select("id").from("people").where("user_name='" + DBConnection.escape(user_name) + "'"), -1);
    if (id == -1)
        return false;
    String email = request.db.lookupString(new Select("email").from("people").whereIdEquals(id));
    if (email == null)
        return false;
    String password = UUID.randomUUID().toString();
    request.db.update("people", "password=md5('" + DBConnection.escape(password) + "')", id);
    StringBuilder message = new StringBuilder("Hello,\n\n").append("Your password for the ").append(getDisplayName()).append(" web site has been reset and is now \"").append(password).append("\". The double quotes are not part of the password. Copy the password, being sure not to select the double quotes, then log into the site by entering your username and pasting the password into the password field. After you log in, change your password by clicking on the popup menu with your name in the upper right and selecting Settings.");
    new Mail(this).send(email, getDisplayName() + " Website Account", message.toString(), false);
    return true;
}
Also used : Mail(email.Mail) FilePathStringBuilder(web.FilePathStringBuilder) Select(db.Select)

Example 9 with Select

use of db.Select in project common by zenlunatics.

the class MailList method getRecipients.

// --------------------------------------------------------------------------
ArrayList<InternetAddress> getRecipients(DBConnection db) {
    String address = null;
    ArrayList<InternetAddress> recipients = new ArrayList<InternetAddress>();
    try {
        List<String> addresses = db.readValues(new Select("email").from("people").join("people", "mail_lists_people").where("email IS NOT NULL AND people.active AND mail_lists_people.mail_lists_id=" + m_id + " AND NOT EXISTS(SELECT 1 FROM mail_lists_digest WHERE mail_lists_digest.people_id=people.id AND mail_lists_digest.mail_lists_id=" + m_id + ")"));
        for (String a : addresses) {
            address = a;
            // System.out.println(a);
            recipients.add(new InternetAddress(address));
        }
        addresses = db.readValues(new Select("email").from("subscribers").where("email IS NOT NULL AND mail_lists_id=" + m_id));
        for (String a : addresses) {
            address = a;
            // System.out.println(a);
            recipients.add(new InternetAddress(address));
        }
    } catch (AddressException e) {
        StringWriter sw = new StringWriter();
        e.printStackTrace(new PrintWriter(sw));
        new Mail(m_site).send(m_name + "@" + m_site.getDomain(), "sean@sonoracohousing.com", "AddressException in MailList.getRecipients()", m_site.getDisplayName() + "\n" + address + "\n" + e.toString() + "\n" + sw.toString(), false);
    }
    if (recipients.size() == 0)
        m_site.log("No recipients for list " + m_name);
    return recipients;
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) StringWriter(java.io.StringWriter) AddressException(javax.mail.internet.AddressException) ArrayList(java.util.ArrayList) Select(db.Select) PrintWriter(java.io.PrintWriter)

Example 10 with Select

use of db.Select in project common by zenlunatics.

the class MailList method loadMessage.

// --------------------------------------------------------------------------
String loadMessage(int message_id, DBConnection db) throws SQLException {
    if (m_store_on_disk)
        return loadMessage(message_id, (ResultSet) null);
    ResultSet rs = db.select(new Select("message").from("ml_" + m_id).whereIdEquals(message_id));
    rs.next();
    String message = rs.getString(1);
    rs.getStatement().close();
    return message;
}
Also used : ResultSet(java.sql.ResultSet) Select(db.Select)

Aggregations

Select (db.Select)67 SQLException (java.sql.SQLException)24 ResultSet (java.sql.ResultSet)21 HTMLWriter (web.HTMLWriter)18 ArrayList (java.util.ArrayList)9 JDBCColumn (db.JDBCColumn)7 File (java.io.File)7 IOException (java.io.IOException)6 MessagingException (javax.mail.MessagingException)6 MimeMessage (javax.mail.internet.MimeMessage)6 AdminTask (web.AdminTask)6 FilePathStringBuilder (web.FilePathStringBuilder)6 Person (app.Person)5 JDBCTable (db.JDBCTable)5 NameValuePairs (db.NameValuePairs)5 View (db.View)5 DBObject (db.DBObject)4 ViewDef (db.ViewDef)4 InternetAddress (javax.mail.internet.InternetAddress)4 Page (app.Page)3