|
| 1 | +<%@ page contentType="text/html;charset=UTF-8" language="java" %> |
| 2 | +<%@ page import="java.sql.*, java.util.Properties, java.io.*" %> |
| 3 | +<!DOCTYPE html> |
| 4 | +<html lang="en"> |
| 5 | +<head> |
| 6 | + <meta charset="UTF-8"/> |
| 7 | + <meta name="viewport" content="width=device-width, initial-scale=1.0"/> |
| 8 | + <title>Contacts — AE6E66™</title> |
| 9 | + <link rel="stylesheet" href="css/style.css"/> |
| 10 | +<script src="js/scroll-preserve.js"></script> |
| 11 | +</head> |
| 12 | +<body> |
| 13 | +<nav class="nav"><div class="nav-inner"> |
| 14 | + <span class="nav-brand">AE6E66™</span> |
| 15 | + <ul class="nav-links"> |
| 16 | + <li><a href="index.jsp">Overview</a></li> |
| 17 | + <li><a href="contacts.jsp" class="active">Contacts</a></li> |
| 18 | + <li><a href="sent.jsp">Sent</a></li> |
| 19 | + <li><a href="status.jsp">Status</a></li> |
| 20 | + </ul> |
| 21 | + <div class="nav-actions"><a href="crawl.jsp" class="nav-cta">Crawl</a></div> |
| 22 | +</div></nav> |
| 23 | + |
| 24 | +<section class="hero" style="padding:4rem 2rem;"> |
| 25 | + <div class="hero-inner"> |
| 26 | + <span class="hero-tag">UK Parliament</span> |
| 27 | + <h1>Contacts</h1> |
| 28 | + <p>House of Lords + House of Commons members crawled from members.parliament.uk.</p> |
| 29 | + </div> |
| 30 | +</section> |
| 31 | + |
| 32 | +<section class="section"> |
| 33 | + <div class="section-inner"> |
| 34 | +<% |
| 35 | + String sourceFilter = request.getParameter("source"); |
| 36 | + Properties dbProps = new Properties(); |
| 37 | + boolean propsLoaded = false; |
| 38 | + Connection conn = null; |
| 39 | + try { |
| 40 | + InputStream dbIn = application.getResourceAsStream("/WEB-INF/db.properties"); |
| 41 | + if (dbIn != null) { dbProps.load(dbIn); dbIn.close(); propsLoaded = true; } |
| 42 | + if (!propsLoaded) { |
| 43 | + String[] tryPaths = { "/opt/tomcat/webapps/ae6e66/WEB-INF/db.properties" }; |
| 44 | + for (String tp : tryPaths) { File f = new File(tp); |
| 45 | + if (f.exists()) { FileInputStream fis = new FileInputStream(f); dbProps.load(fis); fis.close(); propsLoaded = true; break; } } |
| 46 | + } |
| 47 | + Class.forName(dbProps.getProperty("db.driver", "com.mysql.cj.jdbc.Driver")); |
| 48 | + conn = DriverManager.getConnection( |
| 49 | + dbProps.getProperty("db.url", "jdbc:mysql://127.0.0.1:3306/nwe_ae6e66"), |
| 50 | + dbProps.getProperty("db.user", "root"), |
| 51 | + dbProps.getProperty("db.password", "")); |
| 52 | +
|
| 53 | + if (sourceFilter == null || sourceFilter.isEmpty()) { |
| 54 | + // Show sources (HOL / HOC) |
| 55 | + ResultSet rs = conn.createStatement().executeQuery( |
| 56 | + "SELECT source, COUNT(*) AS cnt FROM contacts GROUP BY source ORDER BY source"); |
| 57 | +%> |
| 58 | + <h3>Browse by Chamber</h3> |
| 59 | + <div class="table-wrap"> |
| 60 | + <table> |
| 61 | + <thead><tr><th>Chamber</th><th>Members</th></tr></thead> |
| 62 | + <tbody> |
| 63 | +<% while (rs.next()) { %> |
| 64 | + <tr><td><a href="contacts.jsp?source=<%= rs.getString("source") %>"><%= rs.getString("source") %></a></td><td><%= rs.getInt("cnt") %></td></tr> |
| 65 | +<% } rs.close(); %> |
| 66 | + </tbody> |
| 67 | + </table> |
| 68 | + </div> |
| 69 | +<% |
| 70 | + } else { |
| 71 | + PreparedStatement ps = conn.prepareStatement( |
| 72 | + "SELECT id, name, email, phone, ministry, source FROM contacts WHERE source=? ORDER BY name"); |
| 73 | + ps.setString(1, sourceFilter); |
| 74 | + ResultSet rs = ps.executeQuery(); |
| 75 | +%> |
| 76 | + <h3><%= sourceFilter %> Members</h3> |
| 77 | + <p style="margin-bottom:1rem;"><a href="contacts.jsp">← All Chambers</a></p> |
| 78 | + <div class="table-wrap"> |
| 79 | + <table> |
| 80 | + <thead><tr><th>ID</th><th>Name</th><th>Email</th><th>Phone</th><th>Ministry</th></tr></thead> |
| 81 | + <tbody> |
| 82 | +<% while (rs.next()) { |
| 83 | + String email = rs.getString("email"); |
| 84 | + String phone = rs.getString("phone"); |
| 85 | +%> |
| 86 | + <tr> |
| 87 | + <td><%= rs.getInt("id") %></td> |
| 88 | + <td><%= rs.getString("name") != null ? rs.getString("name") : "" %></td> |
| 89 | + <td><%= email != null && !email.isEmpty() ? email : "—" %></td> |
| 90 | + <td><%= phone != null && !phone.isEmpty() ? phone : "—" %></td> |
| 91 | + <td><%= rs.getString("ministry") != null ? rs.getString("ministry") : "" %></td> |
| 92 | + </tr> |
| 93 | +<% } rs.close(); ps.close(); %> |
| 94 | + </tbody> |
| 95 | + </table> |
| 96 | + </div> |
| 97 | +<% |
| 98 | + } |
| 99 | + } catch (Exception e) { |
| 100 | +%> |
| 101 | + <p style="color:#ef4444;">Database error: <%= e.getMessage() != null ? e.getMessage().replace("<","<") : "unknown" %></p> |
| 102 | + <p style="color:#5f7a5f;font-size:0.8rem;">Props loaded: <%= propsLoaded %></p> |
| 103 | +<% |
| 104 | + } finally { |
| 105 | + if (conn != null) try { conn.close(); } catch (Exception ignored) {} |
| 106 | + } |
| 107 | +%> |
| 108 | + </div> |
| 109 | +</section> |
| 110 | + |
| 111 | +<footer class="footer"><div><span>© 2026 MEARVK LLC. All rights reserved.</span></div></footer> |
| 112 | +</body> |
| 113 | +</html> |
0 commit comments