/kickup/trunk/src/ak/kickup/core/RegistrationMail.txt |
---|
0,0 → 1,16 |
Ваш e-mail был использован при регистрации на "%eventName%". |
Если вы ничего об этом не знаете - просто проигнорируйте это письмо. |
Если же все верно, и это вы зарегистрировались, то ваш регистрационный |
номер: %ident%. Он понадобится, если вы захотите удалить регистрацию |
или изменить свои данные. |
Участие в "%eventName%" стоит %eventPrice% евро. |
Переведите, полжалуйста, деньги на счет: |
%eventMoneyAccount% |
В качестве Verwendungszweck укажите ваш номер, %ident%. |
Если у вас есть вопросы, обращайтесь к организаторам |
(%eventAdmins%) по адресу %eventEmail%. |
/kickup/trunk/src/ak/kickup/core/action/ParticipantAction.java |
---|
27,6 → 27,9 |
import ak.kickup.core.model.ParticipantManager; |
import ak.kickup.core.model.Event; |
import ak.kickup.core.model.EventManager; |
import ak.kickup.core.model.ParticipantAct; |
import ak.kickup.core.model.EventAct; |
import ak.kickup.core.form.ParticipantActBean; |
public final class ParticipantAction |
extends Action |
44,6 → 47,9 |
Event event = (eventId == null) |
? null : EventManager.getInstance().get(eventId, true); |
request.setAttribute("event", event); |
if("submit".equals(mapping.getParameter()) || "update".equals(mapping.getParameter())) |
initLists(request, event); |
} |
if("update".equals(mapping.getParameter())) { |
84,7 → 90,18 |
showForm.set("emailPublic", Boolean.TRUE); |
// acts |
List acts = new ArrayList(event.getActCollection()); |
ParticipantActBean[] a = new ParticipantActBean[acts.size()]; |
Collections.sort(acts, EventManager.ACT_NAME_COMPARATOR); |
for(int i = 0; i < acts.size(); i++) { |
EventAct act = (EventAct)acts.get(i); |
a[i] = new ParticipantActBean(act.getAct(), null); |
} |
showForm.set("acts", a); |
request.setAttribute("event", event); |
initLists(request, event); |
return mapping.findForward("default"); |
} |
else if("login".equals(mapping.getParameter())) { |
103,6 → 120,18 |
throw new UserException("ak.kickup.core.participant.edit.ident.wrong"); |
} |
// acts |
List acts = new ArrayList(event.getActCollection()); |
ParticipantActBean[] a = new ParticipantActBean[acts.size()]; |
Collections.sort(acts, EventManager.ACT_NAME_COMPARATOR); |
for(int i = 0; i < acts.size(); i++) { |
EventAct act = (EventAct)acts.get(i); |
a[i] = new ParticipantActBean(act.getAct(), |
participant.getAct(act.getAct().getId())); |
} |
showForm.set("acts", a); |
// others |
showForm.set("emailPublic", participant.getEmailPublic()); |
showForm.set("name", participant.getName()); |
showForm.set("phone", participant.getPhone()); |
117,6 → 146,7 |
showForm.set("comment", participant.getComment()); |
request.setAttribute("participant", participant); |
initLists(request, event); |
return mapping.findForward("default"); |
} |
else if("unregister".equals(mapping.getParameter())) { |
153,11 → 183,43 |
"ak.kickup.core.participant.edit.registration.unavailable"); |
} |
// acts |
ParticipantActBean[] acts = (ParticipantActBean[])theForm.get("acts"); |
for(int i = 0; i < acts.length; i++) { |
// get bean |
Long actId = StringConverter.parseLong(acts[i].getActId()); |
EventAct act = event.getAct(actId); |
ParticipantAct participantAct = participant.getAct(actId); |
if(acts[i].getSelected() == null || !acts[i].getSelected().booleanValue()) { |
if(participantAct != null) participant.removeAct(participantAct); |
} |
else { |
if(participantAct == null) { |
participantAct = ParticipantManager.getInstance().createAct(); |
participantAct.setParticipant(participant); |
participantAct.setAct(act.getAct()); |
participant.addAct(participantAct); |
} |
participantAct.setComment(acts[i].getComment()); |
} |
} |
// bind |
participant.setIdent(ParticipantManager.getInstance().generateIdent()); |
participant.setEvent(event); |
String email = (String)theForm.get("email"); |
if(ParticipantManager.getInstance().emailExists(participant, email)) { |
request.setAttribute("event", event); |
initLists(request, event); |
throw new UserException("ak.kickup.core.participant.email.nonunique"); |
} |
participant.setEmail(email); |
// others |
participant.setNick((String)theForm.get("nick")); |
participant.setEmail((String)theForm.get("email")); |
participant.setEmailPublic((Boolean)theForm.get("emailPublic")); |
participant.setName((String)theForm.get("name")); |
participant.setPhone((String)theForm.get("phone")); |
173,7 → 235,7 |
ParticipantManager.getInstance().save(participant); |
// FIXME: send email here |
Messages.sendRegistrationMessage(participant, request.getRemoteAddr()); |
response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl()); |
return null; |
191,6 → 253,29 |
throw new ModelSecurityException(); |
} |
// acts |
ParticipantActBean[] acts = (ParticipantActBean[])theForm.get("acts"); |
for(int i = 0; i < acts.length; i++) { |
// get bean |
Long actId = StringConverter.parseLong(acts[i].getActId()); |
EventAct act = event.getAct(actId); |
ParticipantAct participantAct = participant.getAct(actId); |
if(acts[i].getSelected() == null || !acts[i].getSelected().booleanValue()) { |
if(participantAct != null) participant.removeAct(participantAct); |
} |
else { |
if(participantAct == null) { |
participantAct = ParticipantManager.getInstance().createAct(); |
participantAct.setParticipant(participant); |
participantAct.setAct(act.getAct()); |
participant.addAct(participantAct); |
} |
participantAct.setComment(acts[i].getComment()); |
} |
} |
// others |
participant.setEmailPublic((Boolean)theForm.get("emailPublic")); |
participant.setName((String)theForm.get("name")); |
participant.setPhone((String)theForm.get("phone")); |
213,4 → 298,12 |
throw new Exception("unknown mapping parameter"); |
} |
} |
private void initLists(HttpServletRequest request, Event event) |
throws Exception |
{ |
List acts = new ArrayList(event.getActCollection()); |
Collections.sort(acts, EventManager.ACT_NAME_COMPARATOR); |
request.setAttribute("actList", new ObjectList(acts)); |
} |
} |
/kickup/trunk/src/ak/kickup/core/action/AdminParticipantAction.java |
---|
26,6 → 26,9 |
import ak.kickup.core.model.ParticipantManager; |
import ak.kickup.core.model.Event; |
import ak.kickup.core.model.EventManager; |
import ak.kickup.core.model.ParticipantAct; |
import ak.kickup.core.model.EventAct; |
import ak.kickup.core.form.ParticipantActBean; |
public final class AdminParticipantAction |
extends Action |
38,6 → 41,7 |
if("submit".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long eventId = StringConverter.parseLong(theForm.get("event")); |
if(eventId != null) { |
Event event = EventManager.getInstance().get(eventId, false); |
Long participantId = StringConverter.parseLong(theForm.get("id")); |
Participant participant; |
49,8 → 53,12 |
} |
request.setAttribute("event", event); |
request.setAttribute("participant", participant); |
initLists(request, event); |
// FIXME: if a list is changed between "edit" and "submit" then indicies are wrong |
} |
} |
} |
public ActionForward execute(ActionMapping mapping, ActionForm form, |
HttpServletRequest request, HttpServletResponse response) |
98,6 → 106,18 |
showForm.set("privateComment", participant.getPrivateComment()); |
} |
// acts |
List acts = new ArrayList(event.getActCollection()); |
ParticipantActBean[] a = new ParticipantActBean[acts.size()]; |
Collections.sort(acts, EventManager.ACT_NAME_COMPARATOR); |
for(int i = 0; i < acts.size(); i++) { |
EventAct act = (EventAct)acts.get(i); |
a[i] = new ParticipantActBean(act.getAct(), |
participant.getAct(act.getAct().getId())); |
} |
showForm.set("acts", a); |
initLists(request, event); |
request.setAttribute("event", event); |
request.setAttribute("participant", participant); |
return mapping.findForward("default"); |
115,21 → 135,59 |
DynaActionForm theForm = (DynaActionForm)form; |
Long participantId = StringConverter.parseLong(theForm.get("id")); |
Participant participant; |
Event event; |
boolean newParticipant; |
// get instance |
if(participantId == null) { |
Long eventId = StringConverter.parseLong(theForm.get("event")); |
Event event = EventManager.getInstance().get(eventId, false); |
event = EventManager.getInstance().get(eventId, false); |
participant = ParticipantManager.getInstance().create(); |
participant.setIdent(ParticipantManager.getInstance().generateIdent()); |
participant.setEvent(event); |
newParticipant = true; |
} |
else { |
participant = ParticipantManager.getInstance().get(participantId); |
event = participant.getEvent(); |
newParticipant = false; |
} |
// acts |
ParticipantActBean[] acts = (ParticipantActBean[])theForm.get("acts"); |
for(int i = 0; i < acts.length; i++) { |
// get bean |
Long actId = StringConverter.parseLong(acts[i].getActId()); |
EventAct act = event.getAct(actId); |
ParticipantAct participantAct = participant.getAct(actId); |
if(acts[i].getSelected() == null || !acts[i].getSelected().booleanValue()) { |
if(participantAct != null) participant.removeAct(participantAct); |
} |
else { |
if(participantAct == null) { |
participantAct = ParticipantManager.getInstance().createAct(); |
participantAct.setParticipant(participant); |
participantAct.setAct(act.getAct()); |
participant.addAct(participantAct); |
} |
participantAct.setComment(acts[i].getComment()); |
} |
} |
String email = (String)theForm.get("email"); |
if(ParticipantManager.getInstance().emailExists(participant, email)) { |
request.setAttribute("event", event); |
request.setAttribute("participant", participant); |
initLists(request, event); |
throw new UserException("ak.kickup.core.participant.email.nonunique.admin"); |
} |
participant.setEmail(email); |
// others |
participant.setNick((String)theForm.get("nick")); |
participant.setEmail((String)theForm.get("email")); |
participant.setEmailPublic((Boolean)theForm.get("emailPublic")); |
participant.setName((String)theForm.get("name")); |
participant.setPhone((String)theForm.get("phone")); |
146,6 → 204,9 |
participant.setPrivateComment((String)theForm.get("privateComment")); |
ParticipantManager.getInstance().save(participant); |
if(newParticipant) |
Messages.sendRegistrationMessage(participant, null); |
response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl()); |
return null; |
} |
153,4 → 214,12 |
throw new Exception("unknown mapping parameter"); |
} |
} |
private void initLists(HttpServletRequest request, Event event) |
throws Exception |
{ |
List acts = new ArrayList(event.getActCollection()); |
Collections.sort(acts, EventManager.ACT_NAME_COMPARATOR); |
request.setAttribute("actList", new ObjectList(acts)); |
} |
} |
/kickup/trunk/src/ak/kickup/core/action/AdminEventAction.java |
---|
92,7 → 92,7 |
Collections.sort(acts, ActManager.NAME_COMPARATOR); |
for(int i = 0; i < acts.size(); i++) { |
Act act = (Act)acts.get(i); |
a[i] = new EventActBean(act, (event == null) ? null : event.getAct(act.getId())); |
a[i] = new EventActBean(act, event.getAct(act.getId())); |
} |
showForm.set("acts", a); |
/kickup/trunk/src/ak/kickup/core/CoreResources.properties |
---|
2,6 → 2,8 |
ak.kickup.core.act.name.nonunique=Мероприятие с таким названием уже существует |
ak.kickup.core.apartment.name.nonunique=Гостиница с таким названием уже существует |
ak.kickup.core.event.name.nonunique=Пьянка с таким названием уже существует |
ak.kickup.core.participant.email.nonunique=Этот e-mail уже зарегистрирован на эту пьянку. Если вы забыли свой номер - обратитесь к организаторам. |
ak.kickup.core.participant.email.nonunique.admin=Этот e-mail уже зарегистрирован на эту пьянку |
ak.kickup.core.access.denied=Сюда нельзя! |
ak.kickup.core.event.edit.id.wrong=Неизвестная пьянка, выбирайти из списка |
ak.kickup.core.event.edit.name.required=Название обязательно |
31,5 → 33,8 |
ak.kickup.core.participant.edit.ident.wrong=Неизвестный номер |
ak.kickup.core.participant.edit.registration.unavailable=Время регистрации прошло |
ak.kickup.core.participant.edit.unregistration.unavailable=Время отмены регистрации прошло |
ak.kickup.core.mail.send.error=Не могу отправить вам e-mail. Проверьте свой адрес и обратитесь к организаторам. |
ak.kickup.core.mail.read.error=Не могу отправить вам e-mail. Ошибка в системе. |
ak.kickup.core.mail.subject=Регистрация на {0} |
org.apache.struts.taglib.bean.format.sql.timestamp=dd.MM.yyyy HH:mm:ss.SSS |
/kickup/trunk/src/ak/kickup/core/model/Participant.java |
---|
1,6 → 1,11 |
package ak.kickup.core.model; |
import java.util.Date; |
import java.util.Map; |
import java.util.HashMap; |
import java.util.Collections; |
import java.util.Collection; |
import java.util.Iterator; |
import ak.kickup.util.ModelException; |
import ak.kickup.util.ModelSecurityException; |
29,6 → 34,8 |
private Boolean payed; |
private String comment; |
private String privateComment; |
private Collection acts; // Collection(ParticipantAct) |
private Map actsMap = new HashMap(); // Map(Long id -> ParticipantAct) |
protected Participant() |
{ |
286,6 → 293,56 |
this.privateComment = privateComment; |
} |
/** |
* @return Collection(ParticipantAct) |
* |
* @hibernate.bag inverse="true" cascade="all-delete-orphan" lazy="true" |
* @hibernate.collection-key column="participant" |
* @hibernate.collection-one-to-many class="ak.kickup.core.model.ParticipantAct" |
*/ |
protected Collection getActs() |
{ |
return acts; |
} |
public Collection getActCollection() |
{ |
return Collections.unmodifiableCollection(acts); |
} |
/** |
* @param destinations Collection(ParticipantAct) |
*/ |
protected void setActs(Collection acts) |
{ |
this.acts = acts; |
actsMap.clear(); |
if(acts != null) { |
for(Iterator i = acts.iterator(); i.hasNext(); ) { |
ParticipantAct a = (ParticipantAct)i.next(); |
actsMap.put(a.getAct().getId(), a); |
} |
} |
} |
public ParticipantAct getAct(Long actId) |
{ |
return (ParticipantAct)actsMap.get(actId); |
} |
public void addAct(ParticipantAct act) |
{ |
acts.add(act); |
actsMap.put(act.getAct().getId(), act); |
} |
public void removeAct(ParticipantAct act) |
{ |
acts.remove(act); |
actsMap.remove(act.getAct().getId()); |
} |
public boolean equals(Object o) |
{ |
if(o == null || !(o instanceof Participant)) return false; |
/kickup/trunk/src/ak/kickup/core/model/ParticipantAct.java |
---|
0,0 → 1,64 |
package ak.kickup.core.model; |
import java.util.Date; |
import ak.kickup.util.ModelException; |
import ak.kickup.util.ModelSecurityException; |
/** |
* |
* @hibernate.class table="participant_acts" |
*/ |
public class ParticipantAct |
extends GeneralModelObject |
{ |
private Participant participant; |
private Act act; |
private String comment; |
private Date modStamp; |
protected ParticipantAct() |
{ |
} |
/** |
* |
* @hibernate.many-to-one |
*/ |
public Participant getParticipant() |
{ |
return participant; |
} |
public void setParticipant(Participant participant) |
{ |
this.participant = participant; |
} |
/** |
* |
* @hibernate.many-to-one |
*/ |
public Act getAct() |
{ |
return act; |
} |
public void setAct(Act act) |
{ |
this.act = act; |
} |
/** |
* |
* @hibernate.property |
*/ |
public String getComment() |
{ |
return comment; |
} |
public void setComment(String comment) |
{ |
this.comment = comment; |
} |
} |
/kickup/trunk/src/ak/kickup/core/model/ParticipantManager.java |
---|
27,6 → 27,8 |
try { |
HibernateUtil.getConfiguration().addResource( |
"ak/kickup/core/model/Participant.hbm.xml"); |
HibernateUtil.getConfiguration().addResource( |
"ak/kickup/core/model/ParticipantAct.hbm.xml"); |
participantManager = new ParticipantManager(); |
} |
82,6 → 84,30 |
} |
} |
public boolean emailExists(Participant participant, String email) |
throws ModelException |
{ |
try { |
if(participant.getId() == null) |
return ((Integer)HibernateUtil.currentSession().iterate( |
"select count(*) from Participant where email=? and event=?", |
new Object[] { email, participant.getEvent() }, |
new Type[] { Hibernate.STRING, Hibernate.entity(Event.class) } ) |
.next()).intValue() > 0; |
else |
return ((Integer)HibernateUtil.currentSession().iterate( |
"select count(*) from Participant p where email=? and event=? and p!=?", |
new Object[] { email, participant.getEvent(), participant }, |
new Type[] { Hibernate.STRING, Hibernate.entity(Event.class), |
Hibernate.entity(Participant.class) } ) |
.next()).intValue() > 0; |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public String generateIdent() |
throws ModelException |
{ |
172,6 → 198,12 |
} |
} |
public ParticipantAct createAct() |
throws ModelException |
{ |
return new ParticipantAct(); |
} |
public static final Comparator NICK_COMPARATOR = new NickComparator(); |
private static class NickComparator |
/kickup/trunk/src/ak/kickup/core/mail/Messages.java |
---|
0,0 → 1,101 |
package ak.kickup.core.action; |
import java.util.*; |
import java.io.*; |
import java.text.MessageFormat; |
import javax.mail.Session; |
import javax.mail.Message; |
import javax.mail.Transport; |
import javax.mail.internet.MimeMessage; |
import javax.mail.internet.InternetAddress; |
import ak.kickup.util.UserException; |
import ak.kickup.util.StringConverter; |
import ak.kickup.core.model.Participant; |
public abstract class Messages |
{ |
public static final String HOST = "localhost"; |
public static final String CHARSET = "UTF8"; |
public static void send(String from, String to, String subject, String body) |
throws UserException |
{ |
try { |
Properties props = new Properties(); |
props.put("mail.smtp.host", HOST); |
Session session = Session.getInstance(props, null); |
MimeMessage msg = new MimeMessage(session); |
InternetAddress[] address = { new InternetAddress(to) }; |
msg.setFrom(new InternetAddress(from)); |
msg.setRecipients(Message.RecipientType.TO, address); |
msg.setSubject(subject, CHARSET); |
msg.setSentDate(new Date()); |
msg.setText(body, CHARSET); |
Transport.send(msg); |
} |
catch(Exception ex) { |
throw new UserException("ak.kickup.core.mail.send.error"); |
} |
} |
public static void sendRegistrationMessage(Participant participant, String ip) |
throws UserException |
{ |
String subject; |
StringBuffer message = new StringBuffer(); |
// get subject |
ResourceBundle res = ResourceBundle.getBundle("ak/kickup/core/CoreResources"); |
String subjectString = res.getString("ak.kickup.core.mail.subject"); |
subject = MessageFormat.format(subjectString, |
new String[] { participant.getEvent().getName() } ); |
// read message template |
try { |
ClassLoader cl = Messages.class.getClassLoader(); |
if(cl == null) cl = ClassLoader.getSystemClassLoader(); |
BufferedReader file = new BufferedReader(new InputStreamReader(cl.getResourceAsStream( |
"ak/kickup/core/RegistrationMail.txt"), "UTF8")); |
char[] buf = new char[2048]; |
int bufLen; |
while((bufLen = file.read(buf)) >= 0) { |
message.append(buf); |
} |
} |
catch(Exception ex) { |
throw new UserException("ak.kickup.core.mail.read.error"); |
} |
// replace tokens |
replace(message, "ident", participant.getIdent()); |
replace(message, "eventName", participant.getEvent().getName()); |
replace(message, "eventPrice", |
StringConverter.toCurrency(participant.getEvent().getPrice())); |
replace(message, "eventMoneyAccount", participant.getEvent().getMoneyAccount()); |
replace(message, "eventAdmins", participant.getEvent().getAdmins()); |
replace(message, "eventEmail", participant.getEvent().getEmail()); |
replace(message, "", "%"); |
// send message |
send(participant.getEvent().getEmail(), participant.getEmail(), |
subject, message.toString()); |
} |
private static void replace(StringBuffer message, String token, String value) |
{ |
String s = "%" + token + "%"; |
int slen = s.length(); |
int vlen = value.length(); |
int pos = 0; |
while((pos = message.indexOf(s, pos)) >= 0) { |
message.replace(pos, pos + slen, value); |
pos += vlen; |
} |
} |
} |
/kickup/trunk/src/ak/kickup/core/form/ParticipantActBean.java |
---|
0,0 → 1,53 |
package ak.kickup.core.form; |
import ak.kickup.util.StringConverter; |
import ak.kickup.core.model.ParticipantAct; |
import ak.kickup.core.model.Act; |
public final class ParticipantActBean |
{ |
private String actId; |
private String comment; |
private Boolean selected; |
public ParticipantActBean() |
{ |
} |
public ParticipantActBean(Act act, ParticipantAct info) |
{ |
this.actId = StringConverter.toString(act.getId()); |
this.comment = (info == null) ? null : info.getComment(); |
this.selected = Boolean.valueOf(info != null); |
} |
public String getActId() |
{ |
return actId; |
} |
public void setActId(String actId) |
{ |
this.actId = actId; |
} |
public String getComment() |
{ |
return comment; |
} |
public void setComment(String comment) |
{ |
this.comment = comment; |
} |
public Boolean getSelected() |
{ |
return selected; |
} |
public void setSelected(Boolean selected) |
{ |
this.selected = selected; |
} |
} |