1 package org.cacert.gigi.util;
3 import java.io.PrintWriter;
4 import java.sql.PreparedStatement;
5 import java.sql.ResultSet;
6 import java.sql.SQLException;
8 import org.cacert.gigi.User;
9 import org.cacert.gigi.database.DatabaseConnection;
12 public static void writeUserAgreement(int memid, String document,
13 String method, String comment, boolean active, int secmemid)
15 PreparedStatement q = DatabaseConnection
18 "insert into `user_agreements` set `memid`=?, `secmemid`=?,"
19 + " `document`=?,`date`=NOW(), `active`=?,`method`=?,`comment`=?");
21 q.setInt(2, secmemid);
22 q.setString(3, document);
23 q.setInt(4, active ? 1 : 0);
24 q.setString(5, method);
25 q.setString(6, comment);
29 public static boolean checkAssuranceIsPossible(User assurer, User target,
31 if (assurer.getId() == target.getId()) {
33 errOut.println("Cannot assure myself.");
38 PreparedStatement ps = DatabaseConnection
41 "SELECT 1 FROM `notary` where `to`=? and `from`=? AND `deleted`=0");
42 ps.setInt(1, target.getId());
43 ps.setInt(2, assurer.getId());
44 ResultSet rs = ps.executeQuery();
47 errOut.println("You already assured this person.");
53 if (!assurer.canAssure()) {
55 errOut.println("You cannot assure.");
59 } catch (SQLException e) {
65 public synchronized static boolean assure(User assurer, User target,
66 int awarded, String location, String date) throws SQLException {
67 if (!checkAssuranceIsPossible(assurer, target, null)) {
70 User u = new User(target.getId());
71 if (!u.equals(target)) {
74 System.out.println("Would now assure.");
75 if (awarded > assurer.getMaxAssurePoints()) {
79 PreparedStatement ps = DatabaseConnection
82 "INSERT INTO `notary` SET `from`=?, `to`=?, `points`=?, `location`=?, `date`=?");
83 ps.setInt(1, assurer.getId());
84 ps.setInt(2, target.getId());
85 ps.setInt(3, awarded);
86 ps.setString(4, location);
87 ps.setString(5, date);