PrintWriter out = resp.getWriter();
HashMap<String, Object> map = new HashMap<String, Object>();
MyDetailsForm form = new MyDetailsForm(req, getUser(req));
+ MyListingForm listingForm = new MyListingForm(req, getUser(req));
map.put("detailsForm", form);
+ map.put("contactMeForm", listingForm);
getDefaultTemplate().output(out, getLanguage(req), map);
}
if(req.getParameter("processDetails") != null) {
MyDetailsForm form = Form.getForm(req, MyDetailsForm.class);
form.submit(resp.getWriter(), req);
+ } else if (req.getParameter("processContact") != null) {
+ MyListingForm form = Form.getForm(req, MyListingForm.class);
+ form.submit(resp.getWriter(), req);
}
super.doPost(req, resp);
}
--- /dev/null
+package org.cacert.gigi.pages.account;
+
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+import java.sql.SQLException;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.cacert.gigi.GigiApiException;
+import org.cacert.gigi.User;
+import org.cacert.gigi.localisation.Language;
+import org.cacert.gigi.output.Form;
+import org.cacert.gigi.output.template.Template;
+import org.cacert.gigi.pages.Page;
+
+public class MyListingForm extends Form {
+
+ private static Template template;
+
+ static{
+ template = new Template(new InputStreamReader(MyListingForm.class.getResourceAsStream("MyListingForm.templ")));
+ }
+
+ private User target;
+
+ public MyListingForm(HttpServletRequest hsr, User target) {
+ super(hsr);
+ this.target = target;
+ }
+
+ @Override
+ public boolean submit(PrintWriter out, HttpServletRequest req) {
+ if (req.getParameter("listme") != null && req.getParameter("contactinfo") != null) {
+ try {
+ target.setDirectoryListing( !req.getParameter("listme").equals("0"));
+ target.setContactInformation(req.getParameter("contactinfo"));
+ return true;
+ } catch (SQLException e) {
+ new GigiApiException(e).format(out, Page.getLanguage(req));
+ e.printStackTrace();
+ return false;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ protected void outputContent(PrintWriter out, Language l, Map<String, Object> vars) {
+ try {
+ if (target.wantsDirectoryListing()) {
+ vars.put("selected", "selected");
+ vars.put("notSelected", "");
+ vars.put("activeInfo", target.getContactInformation());
+ } else {
+ vars.put("selected", "");
+ vars.put("notSelected", "selected");
+ vars.put("activeInfo", "");
+ }
+ } catch (SQLException e) {
+ new GigiApiException(e).format(out, l);
+ }
+ template.output(out, l, vars);
+ }
+
+}
--- /dev/null
+<table class="wrapper dataTable">
+ <tr>
+ <th colspan="2"><?=_My Listing?></td>
+ </tr>
+ <tr>
+ <td><?=_Directory Listing?>:</td>
+ <td>
+ <select name="listme">
+ <option value="0" <?=$notSelected?>><?=_I don't want to be listed?></option>
+ <option value="1" <?=$selected?>><?=_I want to be listed?></option>
+ </select>
+ </td>
+ </tr>
+ <tr>
+ <td><?=_Contact information?>:</td>
+ <td><textarea name="contactinfo" cols="40" rows="5" wrap="virtual"><?=$activeInfo?></textarea></td>
+ </tr>
+ <tr>
+ <td colspan="2"><input type="submit" name="processContact" value="<?=_Update?>"></td>
+ </tr>
+</table>
\ No newline at end of file