1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.plugins.calendar.web;
35
36 import fr.paris.lutece.plugins.calendar.business.Agenda;
37 import fr.paris.lutece.plugins.calendar.business.CalendarSubscriber;
38 import fr.paris.lutece.plugins.calendar.business.Event;
39 import fr.paris.lutece.plugins.calendar.business.MultiAgenda;
40 import fr.paris.lutece.plugins.calendar.business.OccurrenceEvent;
41 import fr.paris.lutece.plugins.calendar.business.SimpleEvent;
42 import fr.paris.lutece.plugins.calendar.business.category.Category;
43 import fr.paris.lutece.plugins.calendar.business.stylesheet.CalendarStyleSheetHome;
44 import fr.paris.lutece.plugins.calendar.service.AgendaResource;
45 import fr.paris.lutece.plugins.calendar.service.AgendaSubscriberService;
46 import fr.paris.lutece.plugins.calendar.service.CalendarPlugin;
47 import fr.paris.lutece.plugins.calendar.service.CalendarService;
48 import fr.paris.lutece.plugins.calendar.service.CategoryService;
49 import fr.paris.lutece.plugins.calendar.service.EventImageResourceService;
50 import fr.paris.lutece.plugins.calendar.service.EventListService;
51 import fr.paris.lutece.plugins.calendar.service.Utils;
52 import fr.paris.lutece.plugins.calendar.service.search.CalendarSearchService;
53 import fr.paris.lutece.portal.business.stylesheet.StyleSheet;
54 import fr.paris.lutece.portal.service.captcha.CaptchaSecurityService;
55 import fr.paris.lutece.portal.service.i18n.I18nService;
56 import fr.paris.lutece.portal.service.mail.MailService;
57 import fr.paris.lutece.portal.service.message.SiteMessage;
58 import fr.paris.lutece.portal.service.message.SiteMessageException;
59 import fr.paris.lutece.portal.service.message.SiteMessageService;
60 import fr.paris.lutece.portal.service.page.PageNotFoundException;
61 import fr.paris.lutece.portal.service.plugin.Plugin;
62 import fr.paris.lutece.portal.service.plugin.PluginService;
63 import fr.paris.lutece.portal.service.security.LuteceUser;
64 import fr.paris.lutece.portal.service.security.SecurityService;
65 import fr.paris.lutece.portal.service.security.UserNotSignedException;
66 import fr.paris.lutece.portal.service.spring.SpringContextService;
67 import fr.paris.lutece.portal.service.template.AppTemplateService;
68 import fr.paris.lutece.portal.service.util.AppLogService;
69 import fr.paris.lutece.portal.service.util.AppPathService;
70 import fr.paris.lutece.portal.service.util.AppPropertiesService;
71 import fr.paris.lutece.portal.web.constants.Messages;
72 import fr.paris.lutece.portal.web.xpages.XPage;
73 import fr.paris.lutece.portal.web.xpages.XPageApplication;
74 import fr.paris.lutece.util.ReferenceList;
75 import fr.paris.lutece.util.date.DateUtil;
76 import fr.paris.lutece.util.html.HtmlTemplate;
77 import fr.paris.lutece.util.html.Paginator;
78 import fr.paris.lutece.util.string.StringUtil;
79 import fr.paris.lutece.util.url.UrlItem;
80
81 import java.util.ArrayList;
82 import java.util.Calendar;
83 import java.util.Collection;
84 import java.util.Date;
85 import java.util.GregorianCalendar;
86 import java.util.HashMap;
87 import java.util.Iterator;
88 import java.util.List;
89 import java.util.Map;
90
91 import javax.servlet.http.HttpServletRequest;
92 import javax.servlet.http.HttpSession;
93
94 import org.apache.commons.lang.StringUtils;
95
96
97
98
99
100
101 public class CalendarApp implements XPageApplication
102 {
103 public static final String PROPERTY_INVALID_MAIL_TITLE_MESSAGE = "calendar.siteMessage.invalid_mail.title";
104 public static final String PROPERTY_INVALID_MAIL_ERROR_MESSAGE = "calendar.siteMessage.invalid_mail.message";
105
106
107 private static final long serialVersionUID = 3326962245456630378L;
108
109
110 private static final String TEMPLATE_CALENDAR = "skin/plugins/calendar/calendar.html";
111 private static final String TEMPLATE_CALENDAR_LEGEND = "skin/plugins/calendar/calendar_legend.html";
112 private static final String TEMPLATE_CALENDAR_MANAGE_EVENTS = "skin/plugins/calendar/calendar_manage_events.html";
113 private static final String TEMPLATE_CREATE_EVENT_FRONT = "skin/plugins/calendar/create_event_front.html";
114 private static final String TEMPLATE_MODIFY_EVENT_FRONT = "skin/plugins/calendar/modify_event_front.html";
115 private static final String TEMPLATE_SEND_NOTIFICATION_MAIL = "skin/plugins/calendar/notification_email.html";
116 private static final String TEMPLATE_DO_SEARCH_EVENTS = "skin/plugins/calendar/search/dosearch_event_results.html";
117 private static final String TEMPLATE_SHOW_RESULT = "skin/plugins/calendar/search/show_result.html";
118 private static final String TEMPLATE_SEARCH_EVENTS = "skin/plugins/calendar/search/search_events.html";
119 private static final String TEMPLATE_SUBSCRIPTION_FORM = "skin/plugins/calendar/subscription_form.html";
120 private static final String TEMPLATE_EMAIL_FRIEND = "skin/plugins/calendar/email_friend.html";
121 private static final String TEMPLATE_DOWNLOAD_CALENDAR = "skin/plugins/calendar/download_calendar.html";
122 private static final String TEMPLATE_RSS_CALENDAR = "skin/plugins/calendar/rss_calendar.html";
123
124
125 private static final String PROPERTY_PLUGIN_NAME = "calendar";
126
127
128 private static final String PROPERTY_UTIL_DOCUMENT_CLASS = "fr.paris.lutece.plugins.calendar.modules.document.web.DocumentCalendarUtils";
129 private static final String PROPERTY_EMAIL_FRIEND_OBJECT = "calendar.friend.email.object";
130
131
132 private static final String PROPERTY_CONFIRM_REMOVE_TITLE_MESSAGE = "calendar.siteMessage.confirmRemove.title";
133 private static final String PROPERTY_CONFIRM_REMOVE_ALERT_MESSAGE = "calendar.siteMessage.confirmRemove.alertMessage";
134 private static final String PROPERTY_INVALID_DATE_TITLE_MESSAGE = "calendar.siteMessage.invalidDate.title";
135 private static final String PROPERTY_INVALID_DATE_MESSAGE = "calendar.siteMessage.invalidDate.alertMessage";
136 private static final String PROPERTY_INVALID_TIME_TITLE_MESSAGE = "calendar.siteMessage.invalidTime.title";
137 private static final String PROPERTY_INVALID_TIME_MESSAGE = "calendar.siteMessage.invalidTime.alertMessage";
138 private static final String PROPERTY_CAPTCHA_INVALID_MESSAGE = "calendar.siteMessage.invalid_captcha.message";
139 private static final String PROPERTY_CAPTCHA_INVALID_TITLE_MESSAGE = "calendar.siteMessage.invalid_captcha.title";
140 private static final String JSP_PAGE_PORTAL = "jsp/site/Portal.jsp";
141 private static final String JSP_PAGE_RSS = "jsp/site/plugins/calendar/GetCalendarFile.jsp";
142
143
144 private static final String URL_JSP_RETURN_SEND_FRIEND_MAIL = "../../Portal.jsp?page=calendar&action=";
145
146
147 private static final String MARK_BASE_URL = "base_url";
148 private static final String MARK_SENDER_MESSAGE = "sender_message";
149
150
151 private int _nDefaultItemsPerPage = AppPropertiesService.getPropertyInt( Constants.PROPERTY_EVENTS_PER_PAGE, 10 );
152 private String _strCurrentPageIndex;
153 private int _nItemsPerPage;
154 private CaptchaSecurityService _captchaService;
155 private AgendaSubscriberService _agendaSubscriberService = AgendaSubscriberService.getInstance( );
156 private CategoryService _categoryService = CategoryService.getInstance( );
157 private EventListService _eventListService = SpringContextService
158 .getBean( Constants.BEAN_CALENDAR_EVENTLISTSERVICE );
159 private CalendarService _calendarService = SpringContextService.getBean( Constants.BEAN_CALENDAR_CALENDARSERVICE );
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174 public XPage getPage( HttpServletRequest request, int nMode, Plugin plugin ) throws SiteMessageException,
175 UserNotSignedException
176 {
177 XPage page = null;
178
179 String strAction = request.getParameter( Constants.PARAMETER_ACTION );
180 String strPluginName = request.getParameter( Constants.PARAMETER_PAGE );
181 if ( StringUtils.isBlank( strPluginName ) )
182 {
183 strPluginName = CalendarPlugin.PLUGIN_NAME;
184 }
185
186 if ( StringUtils.isNotBlank( strAction ) )
187 {
188 if ( Constants.ACTION_MANAGE_EVENTS.equals( strAction ) )
189 {
190 page = getManageEventsPage( request, plugin );
191 }
192 else if ( Constants.ACTION_ADD_EVENT.equals( strAction ) )
193 {
194 page = getAddEventPage( request, plugin );
195 }
196 else if ( Constants.ACTION_DO_CREATE_EVENT.equals( strAction ) )
197 {
198 doCreateEvent( request, plugin );
199 page = getManageEventsPage( request, plugin );
200 }
201 else if ( Constants.ACTION_MODIFY_EVENT.equals( strAction ) )
202 {
203 page = getModifyEventPage( request, plugin );
204 }
205 else if ( Constants.ACTION_DO_MODIFY_EVENT.equals( strAction ) )
206 {
207 doModifyEvent( request, plugin );
208 page = getManageEventsPage( request, plugin );
209 }
210 else if ( Constants.ACTION_REMOVE_EVENT.equals( strAction ) )
211 {
212 getRemoveEvent( request, plugin );
213 }
214 else if ( Constants.ACTION_DO_REMOVE_EVENT.equals( strAction ) )
215 {
216 doRemoveEvent( request, plugin );
217 page = getManageEventsPage( request, plugin );
218 }
219 else if ( Constants.ACTION_GET_SUBSCRIPTION_PAGE.equals( strAction ) )
220 {
221 page = getSubscriptionPage( request, plugin );
222 }
223 else if ( Constants.ACTION_GET_FRIEND_EMAIL_PAGE.equals( strAction ) )
224 {
225 page = getGetFriendEmailPage( request, plugin );
226 }
227 else if ( Constants.ACTION_GET_DOWNLOAD_PAGE.equals( strAction ) )
228 {
229 page = getDownloadPage( request, plugin );
230 }
231 else if ( Constants.ACTION_SEND_FRIEND_EMAIL.equals( strAction ) )
232 {
233 _agendaSubscriberService.sendFriendMail( request );
234 }
235 else if ( Constants.ACTION_VERIFY_SUBSCRIBE.equals( strAction ) )
236 {
237 doVerifySubscription( request, plugin );
238 }
239 else if ( Constants.ACTION_CONFIRM_UNSUBSCRIBE.equals( strAction ) )
240 {
241 getConfirmUnSubscribe( request );
242 }
243 else if ( Constants.ACTION_UNSUBSCRIBE.equals( strAction ) )
244 {
245 _agendaSubscriberService.doUnSubscribe( request, plugin );
246 }
247 else if ( Constants.ACTION_SEARCH.equals( strAction ) )
248 {
249 page = getSearchPage( request, plugin );
250 }
251 else if ( Constants.ACTION_DO_SEARCH.equals( strAction ) )
252 {
253 page = getSearchResultPage( request, plugin );
254 }
255 else if ( Constants.ACTION_SHOW_RESULT.equals( strAction ) )
256 {
257 page = getShowResultPage( request, plugin );
258 }
259 else if ( Constants.ACTION_RSS.equals( strAction ) )
260 {
261 page = getRssPage( request, plugin );
262 }
263 }
264
265 if ( page == null )
266 {
267 page = getDefaultPage( request, plugin );
268 }
269
270 return page;
271 }
272
273
274
275
276
277
278
279 private XPage getDefaultPage( HttpServletRequest request, Plugin plugin )
280 {
281 XPage page = new XPage( );
282
283 CalendarView view = getView( request );
284 EventList eventlist = _eventListService.newEventList( view.getType( ) );
285
286 MultiAgenda agendaWithOccurences = _calendarService.getMultiAgenda( request );
287 String strDate = getDate( request );
288 CalendarUserOptions options = getUserOptions( request );
289 options.setShowSearchEngine( Boolean.TRUE );
290
291 boolean bIsSelectedDay = false;
292 if ( view.getType( ) == CalendarView.TYPE_DAY )
293 {
294 bIsSelectedDay = true;
295 }
296
297
298 Map<String, Object> model = new HashMap<String, Object>( );
299 model.put( Constants.MARK_PREVIOUS, view.getPrevious( strDate ) );
300 model.put( Constants.MARK_NEXT, view.getNext( strDate ) );
301 model.put( Constants.MARK_TITLE, view.getTitle( strDate, options ) );
302 model.put( Constants.MARK_DATE, strDate );
303 model.put( Constants.MARK_LEGEND, getLegend( request, agendaWithOccurences, options ) );
304 model.put( Constants.MARK_VIEW_CALENDAR, view.getCalendarView( strDate, agendaWithOccurences, options, request ) );
305 model.put( Constants.MARK_SMALL_MONTH_CALENDAR,
306 SmallMonthCalendar.getSmallMonthCalendar( strDate, agendaWithOccurences, options, bIsSelectedDay ) );
307
308
309 String strEventList = StringUtils.EMPTY;
310
311
312 if ( ( eventlist != null ) && ( agendaWithOccurences.getAgendas( ).size( ) != 0 ) )
313 {
314 strEventList = eventlist.getEventList( strDate, agendaWithOccurences, options.getLocale( ), request );
315 }
316
317 model.put( Constants.MARK_EVENT_LIST, strEventList );
318
319 String strRunAppJspUrl = AppPropertiesService.getProperty( Constants.PROPERTY_RUNAPP_JSP_URL );
320 model.put( Constants.MARK_JSP_URL, strRunAppJspUrl );
321
322
323 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_CALENDAR, options.getLocale( ), model );
324 page.setContent( template.getHtml( ) );
325 page.setTitle( I18nService.getLocalizedString( Constants.PROPERTY_TITLE, options.getLocale( ) )
326 + view.getTitle( strDate, options ) );
327 page.setPathLabel( I18nService.getLocalizedString( Constants.PROPERTY_PATH, options.getLocale( ) )
328 + view.getPath( strDate, options ) );
329
330 return page;
331 }
332
333
334
335
336
337
338
339
340 private XPage getManageEventsPage( HttpServletRequest request, Plugin plugin ) throws SiteMessageException
341 {
342 XPage page = null;
343
344 String strCalendarId = request.getParameter( Constants.PARAMETER_CALENDAR_ID );
345 if ( StringUtils.isNotBlank( strCalendarId ) && StringUtils.isNumeric( strCalendarId ) )
346 {
347 page = new XPage( );
348 int nCalendarId = Integer.parseInt( strCalendarId );
349
350
351
352
353
354
355
356
357
358
359
360
361
362 AgendaResource agenda = _calendarService.getAgendaResource( nCalendarId );
363
364 List<SimpleEvent> listEvents = null;
365
366 if ( hasManagerRole( agenda, request ) )
367 {
368 listEvents = _eventListService.getSimpleEvents( nCalendarId, Constants.SORT_ASC );
369 }
370 else
371 {
372 LuteceUser user;
373 try
374 {
375 user = getUser( request );
376 if ( user != null )
377 {
378 listEvents = _eventListService.getSimpleEventsByUserLogin( nCalendarId, user );
379 }
380 }
381 catch ( UserNotSignedException ue )
382 {
383 listEvents = new ArrayList<SimpleEvent>( );
384 }
385 catch ( PageNotFoundException pe )
386 {
387 listEvents = new ArrayList<SimpleEvent>( );
388 }
389 }
390
391 Map<String, Object> model = new HashMap<String, Object>( );
392
393
394 model.put( Constants.MARK_CALENDAR, agenda );
395 model.put( Constants.MARK_EVENT_LIST, listEvents );
396
397 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_CALENDAR_MANAGE_EVENTS,
398 request.getLocale( ), model );
399
400 page.setContent( template.getHtml( ) );
401 page.setTitle( I18nService.getLocalizedString( Constants.PROPERTY_PAGE_TITLE_MANAGE_EVENTS,
402 request.getLocale( ) ) );
403 page.setPathLabel( I18nService.getLocalizedString( Constants.PROPERTY_PAGE_TITLE_MANAGE_EVENTS,
404 request.getLocale( ) ) );
405 }
406 return page;
407 }
408
409
410
411
412
413
414
415
416
417 private XPage getAddEventPage( HttpServletRequest request, Plugin plugin ) throws SiteMessageException
418 {
419 XPage page = null;
420 String strCalendarId = request.getParameter( Constants.PARAMETER_CALENDAR_ID );
421 if ( StringUtils.isNotBlank( strCalendarId ) && StringUtils.isNumeric( strCalendarId ) )
422 {
423 page = new XPage( );
424
425 Map<String, Object> model = new HashMap<String, Object>( );
426
427 model.put( Constants.MARK_CALENDAR_ID, strCalendarId );
428 model.put( Constants.MARK_LOCALE, request.getLocale( ).getLanguage( ) );
429
430 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_CREATE_EVENT_FRONT, request.getLocale( ),
431 model );
432
433 page.setContent( template.getHtml( ) );
434 page.setTitle( I18nService.getLocalizedString( Constants.PROPERTY_PAGE_TITLE_CREATE_EVENT,
435 request.getLocale( ) ) );
436 page.setPathLabel( I18nService.getLocalizedString( Constants.PROPERTY_PAGE_TITLE_CREATE_EVENT,
437 request.getLocale( ) ) );
438 }
439
440 return page;
441
442 }
443
444
445
446
447
448
449
450
451
452 private XPage getModifyEventPage( HttpServletRequest request, Plugin plugin ) throws SiteMessageException,
453 UserNotSignedException
454 {
455 XPage page = null;
456 String strCalendarId = request.getParameter( Constants.PARAMETER_CALENDAR_ID );
457 String strEventId = request.getParameter( Constants.PARAMETER_EVENT_ID );
458 if ( StringUtils.isNotBlank( strCalendarId ) && StringUtils.isNumeric( strCalendarId )
459 && StringUtils.isNotBlank( strEventId ) && StringUtils.isNumeric( strEventId ) )
460 {
461 int nCalendarId = Integer.parseInt( strCalendarId );
462 int nEventId = Integer.parseInt( strEventId );
463 if ( verifiyUserAccess( request, nCalendarId, nEventId, plugin ) )
464 {
465 HashMap<String, Object> model = new HashMap<String, Object>( );
466 model.put( Constants.MARK_EVENT, _eventListService.getEvent( nEventId, plugin ) );
467 model.put( Constants.MARK_CALENDAR_ID, nCalendarId );
468 model.put( Constants.MARK_DEFAULT_SORT_EVENT, request.getParameter( Constants.PARAMETER_SORT_EVENTS ) );
469 model.put( Constants.MARK_LOCALE, request.getLocale( ).getLanguage( ) );
470
471 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MODIFY_EVENT_FRONT,
472 request.getLocale( ), model );
473
474 page = new XPage( );
475 page.setContent( template.getHtml( ) );
476 page.setTitle( I18nService.getLocalizedString( Constants.PROPERTY_PAGE_TITLE_MODIFY_EVENT,
477 request.getLocale( ) ) );
478 page.setPathLabel( I18nService.getLocalizedString( Constants.PROPERTY_PAGE_TITLE_MODIFY_EVENT,
479 request.getLocale( ) ) );
480 }
481 else
482 {
483 SiteMessageService.setMessage( request, Messages.USER_ACCESS_DENIED, SiteMessage.TYPE_STOP );
484 }
485 }
486
487 return page;
488 }
489
490
491
492
493
494
495
496
497
498
499 private void getRemoveEvent( HttpServletRequest request, Plugin plugin ) throws SiteMessageException,
500 UserNotSignedException
501 {
502 String strCalendarId = request.getParameter( Constants.PARAMETER_CALENDAR_ID );
503 String strEventId = request.getParameter( Constants.PARAMETER_EVENT_ID );
504 if ( StringUtils.isNotBlank( strCalendarId ) && StringUtils.isNumeric( strCalendarId )
505 && StringUtils.isNotBlank( strEventId ) && StringUtils.isNumeric( strEventId ) )
506 {
507 int nCalendarId = Integer.parseInt( strCalendarId );
508 int nEventId = Integer.parseInt( strEventId );
509 if ( verifiyUserAccess( request, nCalendarId, nEventId, plugin ) )
510 {
511 UrlItem url = new UrlItem( JSP_PAGE_PORTAL );
512 url.addParameter( Constants.PARAMETER_PAGE, PROPERTY_PLUGIN_NAME );
513 url.addParameter( Constants.PARAMETER_ACTION, Constants.ACTION_DO_REMOVE_EVENT );
514 url.addParameter( Constants.PARAMETER_CALENDAR_ID,
515 request.getParameter( Constants.PARAMETER_CALENDAR_ID ) );
516 url.addParameter( Constants.PARAMETER_EVENT_ID, request.getParameter( Constants.PARAMETER_EVENT_ID ) );
517 SiteMessageService.setMessage( request, PROPERTY_CONFIRM_REMOVE_ALERT_MESSAGE, null,
518 PROPERTY_CONFIRM_REMOVE_TITLE_MESSAGE, url.getUrl( ), null, SiteMessage.TYPE_CONFIRMATION );
519 }
520 else
521 {
522 SiteMessageService.setMessage( request, Messages.USER_ACCESS_DENIED, SiteMessage.TYPE_STOP );
523 }
524 }
525 }
526
527
528
529
530
531
532
533 private XPage getSubscriptionPage( HttpServletRequest request, Plugin plugin )
534 {
535 XPage page = new XPage( );
536 boolean bIsCaptchaEnabled = PluginService.isPluginEnable( Constants.PLUGIN_JCAPTCHA );
537
538 String strBaseUrl = AppPathService.getBaseUrl( request );
539 UrlItem url = new UrlItem( strBaseUrl + JSP_PAGE_PORTAL );
540 url.addParameter( Constants.PARAMETER_PAGE, Constants.PLUGIN_NAME );
541 url.addParameter( Constants.PARAMETER_ACTION, Constants.ACTION_VERIFY_SUBSCRIBE );
542
543 Map<String, Object> model = new HashMap<String, Object>( );
544 model.put( Constants.MARK_JSP_URL, url.getUrl( ) );
545 model.put( Constants.MARK_LOCALE, request.getLocale( ) );
546 model.put( Constants.MARK_CALENDARS_LIST, getListAgenda( request, plugin ) );
547 model.put( Constants.MARK_IS_ACTIVE_CAPTCHA, bIsCaptchaEnabled );
548
549 if ( bIsCaptchaEnabled )
550 {
551 _captchaService = new CaptchaSecurityService( );
552 model.put( Constants.MARK_CAPTCHA, _captchaService.getHtmlCode( ) );
553 }
554
555 HtmlTemplate template = AppTemplateService
556 .getTemplate( TEMPLATE_SUBSCRIPTION_FORM, request.getLocale( ), model );
557
558 page.setContent( template.getHtml( ) );
559 page.setTitle( I18nService.getLocalizedString( Constants.PROPERTY_PAGE_SUBSCRIPTION_TITLE, request.getLocale( ) ) );
560 page.setPathLabel( I18nService.getLocalizedString( Constants.PROPERTY_PAGE_SUBSCRIPTION_TITLE,
561 request.getLocale( ) ) );
562
563 return page;
564 }
565
566
567
568
569
570
571
572 private XPage getGetFriendEmailPage( HttpServletRequest request, Plugin plugin )
573 {
574 XPage page = null;
575 String strCalendarId = request.getParameter( Constants.PARAM_AGENDA );
576 String strEventId = request.getParameter( Constants.PARAMETER_EVENT_ID );
577 if ( StringUtils.isNotBlank( strCalendarId ) && StringUtils.isNumeric( strCalendarId )
578 && StringUtils.isNotBlank( strEventId ) && StringUtils.isNumeric( strEventId ) )
579 {
580 page = new XPage( );
581 Map<String, Object> model = new HashMap<String, Object>( );
582 model.put( Constants.MARK_LOCALE, request.getLocale( ) );
583 model.put( Constants.MARK_EVENT_ID, Integer.parseInt( strEventId ) );
584 model.put( Constants.MARK_CALENDAR_ID, Integer.parseInt( strCalendarId ) );
585
586 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_EMAIL_FRIEND, request.getLocale( ), model );
587
588 page.setContent( template.getHtml( ) );
589 page.setTitle( I18nService.getLocalizedString( Constants.PROPERTY_PAGE_EMAIL_FRIEND_TITLE,
590 request.getLocale( ) ) );
591 page.setPathLabel( I18nService.getLocalizedString( Constants.PROPERTY_PAGE_EMAIL_FRIEND_TITLE,
592 request.getLocale( ) ) );
593 }
594
595 return page;
596 }
597
598
599
600
601
602
603
604 private XPage getDownloadPage( HttpServletRequest request, Plugin plugin )
605 {
606 XPage page = new XPage( );
607 Map<String, Object> model = new HashMap<String, Object>( );
608 model.put( Constants.MARK_LOCALE, request.getLocale( ) );
609 model.put( Constants.MARK_CALENDARS_LIST, getListAgenda( request, plugin ) );
610 model.put( Constants.MARK_EXPORT_STYLESHEET_LIST, getExportSheetList( request, plugin ) );
611
612 HtmlTemplate template = AppTemplateService
613 .getTemplate( TEMPLATE_DOWNLOAD_CALENDAR, request.getLocale( ), model );
614
615 page.setContent( template.getHtml( ) );
616 page.setTitle( I18nService.getLocalizedString( Constants.PROPERTY_PAGE_DOWNLOAND_TITLE, request.getLocale( ) ) );
617 page.setPathLabel( I18nService.getLocalizedString( Constants.PROPERTY_PAGE_DOWNLOAND_TITLE, request.getLocale( ) ) );
618
619 return page;
620 }
621
622
623
624
625
626
627
628 private XPage getSearchPage( HttpServletRequest request, Plugin plugin )
629 {
630 XPage page = new XPage( );
631 Map<String, Object> model = new HashMap<String, Object>( );
632
633 model.put( Constants.MARK_NB_ITEMS_PER_PAGE, Integer.toString( _nDefaultItemsPerPage ) );
634 model.put( Constants.MARK_CALENDARS_LIST, getListAgenda( request, plugin ) );
635 model.put( Constants.MARK_AGENDA, Constants.SPACE );
636 model.put( Constants.MARK_LOCALE, request.getLocale( ) );
637
638 Collection<Category> categoryList = _categoryService.getCategories( plugin );
639 model.put( Constants.MARK_CATEGORY_LIST, getReferenceListCategory( categoryList ) );
640
641 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_SEARCH_EVENTS, request.getLocale( ), model );
642
643 page.setContent( template.getHtml( ) );
644 page.setTitle( I18nService.getLocalizedString( Constants.PROPERTY_PAGE_TITLE_SEARCH, request.getLocale( ) ) );
645 page.setPathLabel( I18nService.getLocalizedString( Constants.PROPERTY_PAGE_TITLE_SEARCH, request.getLocale( ) ) );
646
647 return page;
648 }
649
650
651
652
653
654
655
656
657 private XPage getSearchResultPage( HttpServletRequest request, Plugin plugin ) throws SiteMessageException
658 {
659 String strQuery = request.getParameter( Constants.PARAMETER_QUERY );
660
661 String[] arrayCategory = request.getParameterValues( Constants.PARAMETER_CATEGORY );
662 String[] arrayCalendar = request.getParameterValues( Constants.PARAMETER_CALENDAR_ID );
663
664 String strDateBegin = request.getParameter( Constants.PARAMETER_DATE_START );
665 String strDateEnd = request.getParameter( Constants.PARAMETER_DATE_END );
666 String strPeriod = request.getParameter( Constants.PARAMETER_PERIOD );
667
668 if ( StringUtils.isBlank( strPeriod ) || !StringUtils.isNumeric( strPeriod ) )
669 {
670 strPeriod = Integer.toString( Constants.PROPERTY_PERIOD_NONE );
671 }
672
673 String strAgenda = null;
674
675 String strBaseUrl = AppPathService.getBaseUrl( request );
676 UrlItem url = new UrlItem( JSP_PAGE_PORTAL );
677 url.addParameter( Constants.PARAMETER_QUERY, strQuery == null ? Constants.EMPTY_STRING : strQuery );
678 url.addParameter( Constants.PARAMETER_PAGE, Constants.PLUGIN_NAME );
679 url.addParameter( Constants.PARAMETER_ACTION, Constants.ACTION_DO_SEARCH );
680
681 if ( arrayCalendar != null )
682 {
683 for ( String strAgendaId : arrayCalendar )
684 {
685 url.addParameter( Constants.PARAMETER_CALENDAR_ID, strAgendaId );
686 }
687 }
688 else
689 {
690 arrayCalendar = Utils.getCalendarIds( request );
691 }
692
693 url.addParameter( Constants.PARAMETER_DATE_START, strDateBegin );
694 url.addParameter( Constants.PARAMETER_DATE_END, strDateEnd );
695 url.addParameter( Constants.PARAMETER_PERIOD, strPeriod );
696
697 List<Event> listEvent = null;
698
699 Date dateBegin = null;
700 Date dateEnd = null;
701
702 switch ( Integer.parseInt( strPeriod ) )
703 {
704 case Constants.PROPERTY_PERIOD_NONE:
705 break;
706
707 case Constants.PROPERTY_PERIOD_TODAY:
708 dateBegin = new Date( );
709 dateEnd = new Date( );
710 strDateBegin = DateUtil.getDateString( new Date( ), request.getLocale( ) );
711 strDateEnd = DateUtil.getDateString( new Date( ), request.getLocale( ) );
712 break;
713
714 case Constants.PROPERTY_PERIOD_WEEK:
715
716 Calendar calendar = new GregorianCalendar( );
717 Calendar calendarFirstDay = new GregorianCalendar( );
718 Calendar calendarLastDay = new GregorianCalendar( );
719
720 int nDayOfWeek = calendar.get( Calendar.DAY_OF_WEEK );
721
722 if ( nDayOfWeek == 1 )
723 {
724 nDayOfWeek = 8;
725 }
726
727 calendarFirstDay = calendar;
728 calendarFirstDay.add( Calendar.DATE, Calendar.MONDAY - nDayOfWeek );
729 calendarLastDay = (GregorianCalendar) calendarFirstDay.clone( );
730 calendarLastDay.add( Calendar.DATE, 6 );
731 dateBegin = calendarFirstDay.getTime( );
732 dateEnd = calendarLastDay.getTime( );
733 strDateBegin = DateUtil.getDateString( dateBegin, request.getLocale( ) );
734 strDateEnd = DateUtil.getDateString( dateEnd, request.getLocale( ) );
735
736 break;
737
738 case Constants.PROPERTY_PERIOD_RANGE:
739 if ( StringUtils.isNotBlank( strDateBegin ) && StringUtils.isNotBlank( strDateEnd ) )
740 {
741 dateBegin = DateUtil.formatDate( strDateBegin, request.getLocale( ) );
742 dateEnd = DateUtil.formatDate( strDateEnd, request.getLocale( ) );
743
744 if ( dateBegin == null || !Utils.isValidDate( dateBegin ) || dateEnd == null
745 || !Utils.isValidDate( dateEnd ) )
746 {
747 errorDateFormat( request );
748 }
749 }
750 else
751 {
752 errorDateFormat( request );
753 }
754
755 break;
756 default:
757 break;
758 }
759
760 listEvent = CalendarSearchService.getInstance( ).getSearchResults( arrayCalendar, arrayCategory, strQuery,
761 dateBegin, dateEnd, plugin );
762
763 _strCurrentPageIndex = Paginator.getPageIndex( request, Paginator.PARAMETER_PAGE_INDEX, _strCurrentPageIndex );
764 _nItemsPerPage = Paginator.getItemsPerPage( request, Paginator.PARAMETER_ITEMS_PER_PAGE, _nItemsPerPage,
765 _nDefaultItemsPerPage );
766
767 if ( listEvent == null )
768 {
769 listEvent = new ArrayList<Event>( );
770 }
771
772 Map<String, Object> model = new HashMap<String, Object>( );
773
774 Paginator<Event> paginator = new Paginator<Event>( listEvent, _nItemsPerPage, url.getUrl( ),
775 Constants.PARAMETER_PAGE_INDEX, _strCurrentPageIndex );
776
777
778 if ( ( arrayCalendar != null ) && ( arrayCalendar.length == 1 ) )
779 {
780 strAgenda = arrayCalendar[0];
781 }
782
783 UrlItem urlSubscription = new UrlItem( strBaseUrl + JSP_PAGE_PORTAL );
784 urlSubscription.addParameter( Constants.PARAMETER_PAGE, Constants.PLUGIN_NAME );
785 urlSubscription.addParameter( Constants.PARAMETER_ACTION, Constants.ACTION_GET_SUBSCRIPTION_PAGE );
786 urlSubscription.addParameter( Constants.PARAM_AGENDA, strAgenda );
787
788 UrlItem urlDownload = new UrlItem( strBaseUrl + JSP_PAGE_PORTAL );
789 urlDownload.addParameter( Constants.PARAMETER_PAGE, Constants.PLUGIN_NAME );
790 urlDownload.addParameter( Constants.PARAMETER_ACTION, Constants.ACTION_GET_DOWNLOAD_PAGE );
791
792 UrlItem urlRss = new UrlItem( strBaseUrl + JSP_PAGE_RSS );
793 urlRss.addParameter( Constants.PARAMETER_ACTION, Constants.ACTION_RSS );
794
795 if ( arrayCalendar != null )
796 {
797 for ( String strAgendaId : arrayCalendar )
798 {
799 urlRss.addParameter( Constants.PARAMETER_CALENDAR_ID, strAgendaId );
800 }
801 }
802
803 if ( arrayCategory != null )
804 {
805 for ( String strCategoryId : arrayCategory )
806 {
807 urlRss.addParameter( Constants.PARAMETER_CATEGORY, strCategoryId );
808 }
809 }
810
811 ReferenceList listAgendas = getListAgenda( request, plugin );
812
813 if ( arrayCalendar != null )
814 {
815 listAgendas.checkItems( arrayCalendar );
816 }
817
818 Collection<Category> categoryList = _categoryService.getCategories( plugin );
819 ReferenceList listCategorys = getReferenceListCategory( categoryList );
820
821 if ( arrayCategory != null )
822 {
823 listCategorys.checkItems( arrayCategory );
824 }
825
826
827 List<List<OccurrenceEvent>> listOccurrences = new ArrayList<List<OccurrenceEvent>>( );
828
829 for ( Event event : listEvent )
830 {
831 List<OccurrenceEvent> listOccurrence = _eventListService.getOccurrenceEvents( event.getIdCalendar( ),
832 event.getId( ), Constants.SORT_ASC, plugin );
833 listOccurrences.add( listOccurrence );
834 }
835
836 CalendarUserOptions options = getUserOptions( request );
837 options.setShowSearchEngine( Boolean.TRUE );
838
839 boolean bIsSelectedDay = false;
840 String strDate;
841 if ( StringUtils.isNotBlank( strDateBegin ) && !Constants.NULL.equals( strDateBegin ) )
842 {
843 strDate = Utils.getDate( DateUtil.formatDateLongYear( strDateBegin, request.getLocale( ) ) );
844 if ( strDateBegin.equals( strDateEnd ) )
845 {
846 bIsSelectedDay = true;
847 }
848 }
849 else
850 {
851 strDate = Utils.getDate( new Date( ) );
852 }
853
854 MultiAgenda agendaWithOccurences = _calendarService.getMultiAgenda( request );
855
856 model.put( Constants.MARK_QUERY, ( StringUtils.isNotBlank( strQuery ) ) ? strQuery : StringUtils.EMPTY );
857 model.put( Constants.MARK_SUBSCRIPTION_PAGE, urlSubscription.getUrl( ) );
858 model.put( Constants.MARK_DOWNLOAD_PAGE, urlDownload.getUrl( ) );
859 model.put( Constants.MARK_RSS_PAGE, urlRss.getUrl( ) );
860 model.put( Constants.MARK_DATE_START, ( StringUtils.isNotBlank( strDateBegin ) ) ? strDateBegin
861 : StringUtils.EMPTY );
862 model.put( Constants.MARK_DATE_END, ( StringUtils.isNotBlank( strDateEnd ) ) ? strDateEnd : StringUtils.EMPTY );
863 model.put( Constants.MARK_PERIOD, ( StringUtils.isNotBlank( strPeriod ) ) ? strPeriod : StringUtils.EMPTY );
864 model.put( Constants.MARK_EVENTS_LIST, paginator.getPageItems( ) );
865 model.put( Constants.MARK_PAGINATOR, paginator );
866 model.put( Constants.MARK_NB_ITEMS_PER_PAGE, Integer.toString( _nItemsPerPage ) );
867 model.put( Constants.MARK_CALENDARS_LIST, listAgendas );
868 model.put( Constants.MARK_AGENDA, ( StringUtils.isNotBlank( strAgenda ) ) ? strAgenda : StringUtils.EMPTY );
869 model.put( Constants.MARK_LOCALE, request.getLocale( ) );
870 model.put( Constants.MARK_CATEGORY_LIST, listCategorys );
871 model.put( Constants.MARK_OCCURRENCES_LIST, listOccurrences );
872 model.put( Constants.MARK_SMALL_MONTH_CALENDAR,
873 SmallMonthCalendar.getSmallMonthCalendar( strDate, agendaWithOccurences, options, bIsSelectedDay ) );
874
875 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_DO_SEARCH_EVENTS, request.getLocale( ), model );
876
877 XPage page = new XPage( );
878 page.setContent( template.getHtml( ) );
879 page.setTitle( I18nService.getLocalizedString( Constants.PROPERTY_PAGE_TITLE_SEARCH_RESULT, request.getLocale( ) ) );
880 page.setPathLabel( I18nService.getLocalizedString( Constants.PROPERTY_PAGE_TITLE_SEARCH, request.getLocale( ) ) );
881
882 return page;
883 }
884
885
886
887
888
889
890
891 private XPage getShowResultPage( HttpServletRequest request, Plugin plugin )
892 {
893 XPage page = null;
894 String strDocumentId = request.getParameter( Constants.PARAMETER_DOCUMENT_ID );
895 String strEventId = request.getParameter( Constants.PARAMETER_EVENT_ID );
896 String strPathResult = StringUtils.EMPTY;
897
898 if ( StringUtils.isNotBlank( strEventId ) && StringUtils.isNumeric( strEventId ) )
899 {
900 int nEventId = Integer.parseInt( strEventId );
901
902 SimpleEvent event = _eventListService.getEvent( nEventId, plugin );
903
904 HtmlTemplate template = new HtmlTemplate( );
905
906 if ( event != null )
907 {
908 int nDocumentId = -1;
909
910 if ( StringUtils.isNotBlank( strDocumentId ) && StringUtils.isNumeric( strDocumentId ) )
911 {
912 nDocumentId = Integer.parseInt( strDocumentId );
913 }
914 else if ( event.getDocumentId( ) > -1 )
915 {
916 nDocumentId = event.getDocumentId( );
917 }
918
919 String strTemplateDocument = StringUtils.EMPTY;
920 Plugin pluginModule = PluginService.getPlugin( Constants.PROPERTY_MODULE_CALENDAR );
921
922 if ( ( pluginModule != null ) && pluginModule.isInstalled( ) && ( nDocumentId > 0 ) )
923 {
924 try
925 {
926 IAppUtils documentUtil = (IAppUtils) Class.forName( PROPERTY_UTIL_DOCUMENT_CLASS )
927 .newInstance( );
928 strTemplateDocument = documentUtil.getTemplateDocument( nDocumentId, request );
929 }
930 catch ( Exception e )
931 {
932 AppLogService.error( e );
933 }
934 }
935
936 CalendarUserOptions options = getUserOptions( request );
937 options.setShowSearchEngine( Boolean.TRUE );
938
939 AgendaResource agenda = _calendarService.getAgendaResource( event.getIdCalendar( ) );
940
941 MultiAgenda agendaWithOccurences = _calendarService.getMultiAgenda( request );
942
943 String strRole = agenda.getRole( );
944
945 boolean bIsUserAuthorized = false;
946
947 if ( hasManagerRole( agenda, request ) || hasRole( strRole, request )
948 || Constants.PROPERTY_ROLE_NONE.equals( strRole ) )
949 {
950 bIsUserAuthorized = true;
951 }
952
953 Map<String, Object> model = new HashMap<String, Object>( );
954
955 if ( bIsUserAuthorized )
956 {
957 String strBaseUrl = AppPathService.getBaseUrl( request );
958 UrlItem urlEmailFriend = new UrlItem( strBaseUrl + JSP_PAGE_PORTAL );
959 urlEmailFriend.addParameter( Constants.PARAMETER_PAGE, Constants.PLUGIN_NAME );
960 urlEmailFriend.addParameter( Constants.PARAMETER_ACTION, Constants.ACTION_GET_FRIEND_EMAIL_PAGE );
961
962 UrlItem urlRss = new UrlItem( strBaseUrl + JSP_PAGE_RSS );
963 urlRss.addParameter( Constants.PARAMETER_ACTION, Constants.ACTION_RSS );
964
965 UrlItem urlSubscription = new UrlItem( strBaseUrl + JSP_PAGE_PORTAL );
966 urlSubscription.addParameter( Constants.PARAMETER_PAGE, Constants.PLUGIN_NAME );
967 urlSubscription.addParameter( Constants.PARAMETER_ACTION, Constants.ACTION_GET_SUBSCRIPTION_PAGE );
968
969 UrlItem urlDownload = new UrlItem( strBaseUrl + JSP_PAGE_PORTAL );
970 urlDownload.addParameter( Constants.PARAMETER_PAGE, Constants.PLUGIN_NAME );
971 urlDownload.addParameter( Constants.PARAMETER_ACTION, Constants.ACTION_GET_DOWNLOAD_PAGE );
972
973 event.setImageUrl( EventImageResourceService.getInstance( ).getResourceImageEvent( event.getId( ) ) );
974 model.put( Constants.MARK_EVENT, event );
975 model.put( Constants.MARK_DOCUMENT, strTemplateDocument );
976 model.put( Constants.MARK_AGENDA, agenda );
977 model.put( Constants.MARK_EMAIL_FRIEND_PAGE, urlEmailFriend.getUrl( ) );
978 model.put( Constants.MARK_RSS_PAGE, urlRss.getUrl( ) );
979 model.put( Constants.MARK_SUBSCRIPTION_PAGE, urlSubscription.getUrl( ) );
980 model.put( Constants.MARK_DOWNLOAD_PAGE, urlDownload.getUrl( ) );
981 }
982
983 model.put( Constants.MARK_IS_AUTHORIZED, bIsUserAuthorized );
984 model.put( Constants.MARK_SMALL_MONTH_CALENDAR, SmallMonthCalendar.getSmallMonthCalendar(
985 Utils.getDate( event.getDate( ) ), agendaWithOccurences, options, true ) );
986 template = AppTemplateService.getTemplate( TEMPLATE_SHOW_RESULT, request.getLocale( ), model );
987 strPathResult = event.getTitle( );
988 }
989
990 page = new XPage( );
991 page.setContent( template.getHtml( ) );
992 page.setTitle( I18nService.getLocalizedString( Constants.PROPERTY_PAGE_TITLE_SEARCH_RESULT,
993 request.getLocale( ) ) );
994 page.setPathLabel( strPathResult );
995 }
996 return page;
997 }
998
999
1000
1001
1002
1003
1004
1005 private XPage getRssPage( HttpServletRequest request, Plugin plugin )
1006 {
1007 Collection<Category> categoryList = _categoryService.getCategories( plugin );
1008
1009 Map<String, Object> model = new HashMap<String, Object>( );
1010 model.put( Constants.MARK_LOCALE, request.getLocale( ) );
1011 model.put( Constants.MARK_CALENDARS_LIST, getListAgenda( request, plugin ) );
1012 model.put( Constants.MARK_CATEGORY_LIST, getReferenceListCategory( categoryList ) );
1013 model.put( Constants.MARK_CATEGORY_DEFAULT_LIST, StringUtils.EMPTY );
1014
1015 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_RSS_CALENDAR, request.getLocale( ), model );
1016
1017 XPage page = new XPage( );
1018 page.setContent( template.getHtml( ) );
1019 page.setTitle( I18nService.getLocalizedString( Constants.PROPERTY_PAGE_RSS_TITLE, request.getLocale( ) ) );
1020 page.setPathLabel( I18nService.getLocalizedString( Constants.PROPERTY_PAGE_RSS_TITLE, request.getLocale( ) ) );
1021
1022 return page;
1023 }
1024
1025
1026
1027
1028
1029
1030
1031 public void getConfirmUnSubscribe( HttpServletRequest request ) throws SiteMessageException
1032 {
1033 UrlItem urlItem = new UrlItem( request.getRequestURI( ) );
1034 urlItem.addParameter( Constants.PARAMETER_ACTION, Constants.ACTION_UNSUBSCRIBE );
1035 urlItem.addParameter( Constants.PARAMETER_EMAIL, request.getParameter( Constants.PARAMETER_EMAIL ) );
1036 urlItem.addParameter( Constants.PARAM_AGENDA, request.getParameter( Constants.PARAM_AGENDA ) );
1037 SiteMessageService.setMessage( request, Constants.PROPERTY_CONFIRM_UNSUBSCRIPTION_ALERT_MESSAGE, null,
1038 Constants.PROPERTY_CONFIRM_UNSUBSCRIPTION_TITLE_MESSAGE, urlItem.getUrl( ), null,
1039 SiteMessage.TYPE_CONFIRMATION );
1040 }
1041
1042
1043
1044
1045
1046
1047 private String getDate( HttpServletRequest request )
1048 {
1049 String strDate = request.getParameter( Constants.PARAM_DATE );
1050
1051 if ( !Utils.isValid( strDate ) )
1052 {
1053 strDate = Utils.getDateToday( );
1054 }
1055
1056 return strDate;
1057 }
1058
1059
1060
1061
1062
1063
1064 private CalendarView getView( HttpServletRequest request )
1065 {
1066 CalendarView view = null;
1067 String strView = request.getParameter( Constants.PARAM_VIEW );
1068
1069 if ( strView != null )
1070 {
1071 if ( strView.equals( Constants.VIEW_DAY ) )
1072 {
1073 view = new DayCalendarView( );
1074 }
1075 else if ( strView.equals( Constants.VIEW_WEEK ) )
1076 {
1077 view = new WeekCalendarView( );
1078 }
1079 else if ( strView.equals( Constants.VIEW_MONTH ) )
1080 {
1081 view = new MonthCalendarView( );
1082 }
1083 else
1084 {
1085
1086 view = new MonthCalendarView( );
1087 }
1088
1089 HttpSession session = request.getSession( true );
1090 session.setAttribute( Constants.ATTRIBUTE_CALENDAR_VIEW, view );
1091 }
1092 else
1093 {
1094 HttpSession session = request.getSession( );
1095 CalendarView viewCurrentSession = (CalendarView) session.getAttribute( Constants.ATTRIBUTE_CALENDAR_VIEW );
1096
1097 if ( viewCurrentSession != null )
1098 {
1099 view = viewCurrentSession;
1100 }
1101 else
1102 {
1103
1104 view = new MonthCalendarView( );
1105 }
1106 }
1107
1108 return view;
1109 }
1110
1111
1112
1113
1114
1115
1116
1117 private CalendarUserOptions getUserOptions( HttpServletRequest request )
1118 {
1119 CalendarUserOptions options = new CalendarUserOptions( );
1120 options.setLocale( request.getLocale( ) );
1121 options.setDayOffDisplayed( true );
1122
1123 return options;
1124 }
1125
1126
1127
1128
1129
1130
1131
1132
1133 private String getLegend( HttpServletRequest request, MultiAgenda multiAgenda, CalendarUserOptions options )
1134 {
1135 String strLegend = StringUtils.EMPTY;
1136
1137 if ( multiAgenda != null && !multiAgenda.getAgendas( ).isEmpty( ) )
1138 {
1139 Map<String, Object> model = new HashMap<String, Object>( );
1140
1141 List<Agenda> listAgendas = multiAgenda.getAgendas( );
1142 List<AgendaResource> listAgendaResource = new ArrayList<AgendaResource>( );
1143
1144 for ( Agenda agenda : listAgendas )
1145 {
1146 if ( agenda != null )
1147 {
1148 AgendaResource agendaResource = _calendarService.getAgendaResource( agenda.getKeyName( ) );
1149 if ( agendaResource != null )
1150 {
1151 listAgendaResource.add( agendaResource );
1152 }
1153 }
1154 }
1155
1156 model.put( Constants.MARK_AGENDA_RESOURCE_LIST, listAgendaResource );
1157
1158 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_CALENDAR_LEGEND, options.getLocale( ),
1159 model );
1160 strLegend = template.getHtml( );
1161 }
1162
1163 return strLegend;
1164 }
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174 private void doCreateEvent( HttpServletRequest request, Plugin plugin ) throws SiteMessageException
1175 {
1176 String strCalendarId = request.getParameter( Constants.PARAMETER_CALENDAR_ID );
1177 if ( StringUtils.isNotBlank( strCalendarId ) && StringUtils.isNumeric( strCalendarId ) )
1178 {
1179
1180 String strDate = request.getParameter( Constants.PARAMETER_EVENT_DATE );
1181 String strEventTitle = request.getParameter( Constants.PARAMETER_EVENT_TITLE );
1182
1183 int nCalendarId = Integer.parseInt( strCalendarId );
1184
1185 verifyFieldFilled( request, strDate );
1186 verifyFieldFilled( request, strEventTitle );
1187
1188
1189 Date dateEvent = DateUtil.formatDate( strDate, request.getLocale( ) );
1190
1191 if ( dateEvent == null )
1192 {
1193 errorDateFormat( request );
1194 }
1195
1196 SimpleEvent event = new SimpleEvent( );
1197 event.setIdCalendar( nCalendarId );
1198 event.setDate( dateEvent );
1199 event.setDateEnd( dateEvent );
1200
1201 String strTimeStart = request.getParameter( Constants.PARAMETER_EVENT_TIME_START );
1202 String strTimeEnd = request.getParameter( Constants.PARAMETER_EVENT_TIME_END );
1203
1204 if ( !Utils.checkTime( strTimeStart ) || !Utils.checkTime( strTimeEnd ) )
1205 {
1206 errorTimeFormat( request );
1207 }
1208
1209 event.setDateTimeStart( strTimeStart );
1210 event.setDateTimeEnd( strTimeEnd );
1211 event.setTitle( request.getParameter( Constants.PARAMETER_EVENT_TITLE ) );
1212 event.setDescription( Constants.EMPTY_STRING );
1213 event.setOccurrence( 1 );
1214
1215 AgendaResource agenda = _calendarService.getAgendaResource( nCalendarId );
1216
1217
1218 if ( hasManagerRole( agenda, request ) )
1219 {
1220
1221 event.setStatus( AppPropertiesService.getProperty( Constants.PROPERTY_EVENT_STATUS_DEFAULT ) );
1222 }
1223 else
1224 {
1225
1226 event.setStatus( AppPropertiesService.getProperty( Constants.PROPERTY_EVENT_STATUS_TENTATIVE ) );
1227 }
1228
1229 LuteceUser user;
1230 try
1231 {
1232 user = getUser( request );
1233 _eventListService.doAddEvent( event, user, plugin );
1234 }
1235 catch ( PageNotFoundException e )
1236 {
1237 _eventListService.doAddEvent( event, null, plugin );
1238 }
1239 catch ( UserNotSignedException e )
1240 {
1241 _eventListService.doAddEvent( event, null, plugin );
1242 }
1243
1244
1245 int nSubscriber = _agendaSubscriberService.getSubscriberNumber( nCalendarId, plugin );
1246 Collection<CalendarSubscriber> listSubscribers = new ArrayList<CalendarSubscriber>( );
1247 if ( nSubscriber > 0
1248 && AppPropertiesService.getProperty( Constants.PROPERTY_EVENT_STATUS_CONFIRMED ).equals(
1249 event.getStatus( ) ) )
1250 {
1251 listSubscribers = _agendaSubscriberService.getSubscribers( nCalendarId, plugin );
1252 }
1253
1254 CalendarSubscriber webmaster = new CalendarSubscriber( );
1255 webmaster.setEmail( AppPropertiesService.getProperty( Constants.PROPERTY_WEBMASTER_EMAIL ) );
1256 listSubscribers.add( webmaster );
1257 _agendaSubscriberService.sendSubscriberMail( request, listSubscribers, event, nCalendarId );
1258 }
1259 }
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270 private void doModifyEvent( HttpServletRequest request, Plugin plugin ) throws SiteMessageException,
1271 UserNotSignedException
1272 {
1273 String strCalendarId = request.getParameter( Constants.PARAMETER_CALENDAR_ID );
1274 String strEventId = request.getParameter( Constants.PARAMETER_EVENT_ID );
1275 if ( StringUtils.isNotBlank( strCalendarId ) && StringUtils.isNumeric( strCalendarId )
1276 && StringUtils.isNotBlank( strEventId ) && StringUtils.isNumeric( strEventId ) )
1277 {
1278 int nCalendarId = Integer.parseInt( strCalendarId );
1279 int nEventId = Integer.parseInt( strEventId );
1280 if ( verifiyUserAccess( request, nCalendarId, nEventId, plugin ) )
1281 {
1282 String strEventDate = request.getParameter( Constants.PARAMETER_EVENT_DATE );
1283 verifyFieldFilled( request, strEventDate );
1284
1285
1286 Date dateEvent = DateUtil.formatDate( strEventDate, request.getLocale( ) );
1287
1288 if ( dateEvent == null )
1289 {
1290 errorDateFormat( request );
1291 }
1292
1293 SimpleEvent event = _eventListService.getEvent( nEventId, plugin );
1294 AgendaResource agenda = _calendarService.getAgendaResource( nCalendarId );
1295
1296 List<OccurrenceEvent> listOccurrenceEvents = _eventListService.getOccurrenceEvents( nCalendarId,
1297 nEventId, Constants.SORT_ASC, plugin );
1298
1299
1300 if ( hasManagerRole( agenda, request ) )
1301 {
1302 for ( OccurrenceEvent occurrenceEvent : listOccurrenceEvents )
1303 {
1304 if ( event.getDate( ).equals( occurrenceEvent.getDate( ) ) )
1305 {
1306 event.setStatus( occurrenceEvent.getStatus( ) );
1307 break;
1308 }
1309 }
1310 }
1311 else
1312 {
1313 event.setStatus( AppPropertiesService.getProperty( Constants.PROPERTY_EVENT_STATUS_TENTATIVE ) );
1314 for ( OccurrenceEvent occurrenceEvent : listOccurrenceEvents )
1315 {
1316 occurrenceEvent.setStatus( event.getStatus( ) );
1317 _eventListService.doModifyOccurrenceEvent( occurrenceEvent, plugin );
1318 }
1319 }
1320
1321 event.setDate( dateEvent );
1322
1323 String strTimeStart = request.getParameter( Constants.PARAMETER_EVENT_TIME_START );
1324 String strTimeEnd = request.getParameter( Constants.PARAMETER_EVENT_TIME_END );
1325
1326 if ( !Utils.checkTime( strTimeStart ) || !Utils.checkTime( strTimeEnd ) )
1327 {
1328 errorTimeFormat( request );
1329 }
1330
1331 event.setDateTimeStart( strTimeStart );
1332 event.setDateTimeEnd( strTimeEnd );
1333 event.setTitle( request.getParameter( Constants.PARAMETER_EVENT_TITLE ) );
1334
1335 _eventListService.doModifySimpleEvent( event, true, getUser( request ), plugin );
1336 }
1337 else
1338 {
1339 SiteMessageService.setMessage( request, Messages.USER_ACCESS_DENIED, SiteMessage.TYPE_STOP );
1340 }
1341 }
1342 }
1343
1344
1345
1346
1347
1348
1349
1350
1351 private void doRemoveEvent( HttpServletRequest request, Plugin plugin ) throws UserNotSignedException,
1352 SiteMessageException
1353 {
1354 String strCalendarId = request.getParameter( Constants.PARAMETER_CALENDAR_ID );
1355 String strEventId = request.getParameter( Constants.PARAMETER_EVENT_ID );
1356 if ( StringUtils.isNotBlank( strCalendarId ) && StringUtils.isNumeric( strCalendarId )
1357 && StringUtils.isNotBlank( strEventId ) && StringUtils.isNumeric( strEventId ) )
1358 {
1359 int nCalendarId = Integer.parseInt( strCalendarId );
1360 int nEventId = Integer.parseInt( strEventId );
1361 if ( verifiyUserAccess( request, nCalendarId, nEventId, plugin ) )
1362 {
1363 _eventListService.doRemoveEvent( nCalendarId, nEventId, getUser( request ), plugin );
1364 }
1365 else
1366 {
1367 SiteMessageService.setMessage( request, Messages.USER_ACCESS_DENIED, SiteMessage.TYPE_STOP );
1368 }
1369 }
1370 }
1371
1372
1373
1374
1375
1376
1377
1378 private void doVerifySubscription( HttpServletRequest request, Plugin plugin ) throws SiteMessageException
1379 {
1380 String strEmail = request.getParameter( Constants.PARAMETER_EMAIL );
1381 if ( StringUtils.isNotBlank( strEmail ) && StringUtil.checkEmail( strEmail ) )
1382 {
1383 if ( _captchaService != null && !_captchaService.validate( request ) )
1384 {
1385
1386 SiteMessageService.setMessage( request, PROPERTY_CAPTCHA_INVALID_MESSAGE,
1387 PROPERTY_CAPTCHA_INVALID_TITLE_MESSAGE, SiteMessage.TYPE_INFO );
1388 }
1389 else
1390 {
1391 String strAgenda = request.getParameter( Constants.PARAM_AGENDA );
1392 if ( StringUtils.isNotBlank( strAgenda ) && StringUtils.isNumeric( strAgenda ) )
1393 {
1394 int nAgendaId = Integer.parseInt( strAgenda );
1395 AgendaResource agenda = _calendarService.getAgendaResource( nAgendaId );
1396 _agendaSubscriberService.doNotificationSubscription( agenda, request, plugin );
1397 }
1398 }
1399 }
1400 else
1401 {
1402 SiteMessageService.setMessage( request, PROPERTY_INVALID_MAIL_ERROR_MESSAGE, new String[] { strEmail },
1403 PROPERTY_INVALID_MAIL_TITLE_MESSAGE, SiteMessage.TYPE_STOP );
1404 }
1405 }
1406
1407
1408
1409
1410
1411
1412
1413
1414 private void verifyFieldFilled( HttpServletRequest request, String strField ) throws SiteMessageException
1415 {
1416 if ( StringUtils.isBlank( strField ) )
1417 {
1418 SiteMessageService.setMessage( request, Messages.MANDATORY_FIELDS, SiteMessage.TYPE_STOP );
1419 }
1420 }
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431 private boolean verifiyUserAccess( HttpServletRequest request, int nCalendarId, int nEventId, Plugin plugin )
1432 throws UserNotSignedException
1433 {
1434 boolean bIsVerified = false;
1435 AgendaResource agenda = _calendarService.getAgendaResource( nCalendarId );
1436
1437 if ( hasManagerRole( agenda, request ) )
1438 {
1439 bIsVerified = true;
1440 }
1441 else
1442 {
1443 LuteceUser user = getUser( request );
1444 if ( user != null )
1445 {
1446 List<SimpleEvent> listEvents = _eventListService.getSimpleEventsByUserLogin( nCalendarId, user );
1447 for ( SimpleEvent event : listEvents )
1448 {
1449 if ( event.getId( ) == nEventId )
1450 {
1451 bIsVerified = true;
1452 break;
1453 }
1454 }
1455 }
1456 }
1457 return bIsVerified;
1458 }
1459
1460
1461
1462
1463
1464
1465
1466 private void errorDateFormat( HttpServletRequest request ) throws SiteMessageException
1467 {
1468 SiteMessageService.setMessage( request, PROPERTY_INVALID_DATE_MESSAGE, null,
1469 PROPERTY_INVALID_DATE_TITLE_MESSAGE, null, null, SiteMessage.TYPE_STOP );
1470 }
1471
1472
1473
1474
1475
1476
1477
1478 private void errorTimeFormat( HttpServletRequest request ) throws SiteMessageException
1479 {
1480 SiteMessageService.setMessage( request, PROPERTY_INVALID_TIME_MESSAGE, null,
1481 PROPERTY_INVALID_TIME_TITLE_MESSAGE, null, null, SiteMessage.TYPE_STOP );
1482 }
1483
1484
1485
1486
1487
1488
1489
1490 public void doSubscription( HttpServletRequest request ) throws SiteMessageException
1491 {
1492 AgendaSubscriberService.getInstance( ).doValidationSubscription( request );
1493 }
1494
1495
1496
1497
1498
1499
1500
1501
1502 public String doSendToFriend( HttpServletRequest request ) throws SiteMessageException
1503 {
1504
1505 String strIdEvent = request.getParameter( Constants.PARAMETER_EVENT_ID );
1506 String strIdCalendar = request.getParameter( Constants.PARAMETER_CALENDAR_ID );
1507 String strFriendEmail = request.getParameter( Constants.PARAMETER_SENDER_FRIEND_EMAIL );
1508 String strSenderFirstName = request.getParameter( Constants.PARAMETER_SENDER_FIRST_NAME );
1509 String strSenderLastName = request.getParameter( Constants.PARAMETER_SENDER_LAST_NAME );
1510 String strSenderEmail = request.getParameter( Constants.PARAMETER_SENDER_EMAIL );
1511 String strSenderMessage = request.getParameter( Constants.PARAMETER_SENDER_MESSAGE );
1512 int nIdCalendar = Integer.parseInt( strIdCalendar );
1513
1514
1515 if ( StringUtils.isEmpty( strFriendEmail ) || StringUtils.isEmpty( strSenderFirstName )
1516 || StringUtils.isEmpty( strSenderLastName ) || StringUtils.isEmpty( strSenderEmail )
1517 || StringUtils.isEmpty( strSenderMessage ) )
1518 {
1519 SiteMessageService.setMessage( request, Messages.MANDATORY_FIELDS, Messages.MANDATORY_FIELDS,
1520 SiteMessage.TYPE_STOP );
1521 }
1522
1523 if ( ( strFriendEmail == null ) || !StringUtil.checkEmail( strFriendEmail ) )
1524 {
1525 Object[] args = { strFriendEmail };
1526 SiteMessageService.setMessage( request, PROPERTY_INVALID_MAIL_ERROR_MESSAGE, args,
1527 PROPERTY_INVALID_MAIL_TITLE_MESSAGE, SiteMessage.TYPE_STOP );
1528 }
1529
1530 if ( ( strSenderEmail == null ) || !StringUtil.checkEmail( strSenderEmail ) )
1531 {
1532 Object[] args = { strSenderEmail };
1533 SiteMessageService.setMessage( request, PROPERTY_INVALID_MAIL_ERROR_MESSAGE, args,
1534 PROPERTY_INVALID_MAIL_TITLE_MESSAGE, SiteMessage.TYPE_STOP );
1535 }
1536
1537 String strSenderName = strSenderFirstName + Constants.SPACE + strSenderLastName;
1538
1539
1540 String strObject = I18nService.getLocalizedString( PROPERTY_EMAIL_FRIEND_OBJECT, request.getLocale( ) );
1541 String strBaseUrl = AppPathService.getBaseUrl( request );
1542
1543 Map<String, Object> emailModel = new HashMap<String, Object>( );
1544 emailModel.put( MARK_SENDER_MESSAGE, strSenderMessage );
1545 emailModel.put( MARK_BASE_URL, strBaseUrl );
1546 emailModel.put( Constants.PARAMETER_EVENT_ID, strIdEvent );
1547 emailModel.put( Constants.PARAMETER_CALENDAR_ID, nIdCalendar );
1548 emailModel.put( Constants.MARK_ACTION, Constants.ACTION_SHOW_RESULT );
1549
1550 HtmlTemplate templateAgenda = AppTemplateService.getTemplate( TEMPLATE_SEND_NOTIFICATION_MAIL,
1551 request.getLocale( ), emailModel );
1552
1553 String strNewsLetterCode = templateAgenda.getHtml( );
1554
1555 MailService.sendMailHtml( strFriendEmail, strSenderName, strSenderEmail, strObject, strNewsLetterCode );
1556
1557 return URL_JSP_RETURN_SEND_FRIEND_MAIL + Constants.ACTION_SHOW_RESULT + "&" + Constants.PARAMETER_EVENT_ID
1558 + "=" + strIdEvent + "&" + Constants.PARAM_AGENDA + "=" + strIdCalendar;
1559 }
1560
1561
1562
1563
1564
1565
1566
1567 public ReferenceList getListAgenda( HttpServletRequest request, Plugin plugin )
1568 {
1569 ReferenceList listAgendas = new ReferenceList( );
1570
1571 for ( AgendaResource a : _calendarService.getAgendaResources( request ) )
1572 {
1573 if ( a != null )
1574 {
1575 listAgendas.addItem( a.getId( ), a.getName( ) );
1576 }
1577 }
1578
1579 return listAgendas;
1580 }
1581
1582
1583
1584
1585
1586
1587
1588 public ReferenceList getExportSheetList( HttpServletRequest request, Plugin plugin )
1589 {
1590 ReferenceList listSheets = new ReferenceList( );
1591
1592 Collection<StyleSheet> collectionSheets = CalendarStyleSheetHome.getStyleSheetList( plugin );
1593
1594 if ( collectionSheets != null )
1595 {
1596 Iterator<StyleSheet> i = collectionSheets.iterator( );
1597
1598 while ( i.hasNext( ) )
1599 {
1600 StyleSheet sheet = i.next( );
1601 listSheets.addItem( sheet.getId( ), sheet.getDescription( ) );
1602 }
1603 }
1604
1605 return listSheets;
1606 }
1607
1608
1609
1610
1611
1612
1613 private ReferenceList getReferenceListCategory( Collection<Category> collection )
1614 {
1615 ReferenceList list = new ReferenceList( );
1616
1617 if ( collection != null )
1618 {
1619 Iterator<Category> i = collection.iterator( );
1620
1621 while ( i.hasNext( ) )
1622 {
1623 Category category = i.next( );
1624 list.addItem( category.getId( ), category.getName( ) );
1625 }
1626 }
1627
1628 return list;
1629 }
1630
1631
1632
1633
1634
1635
1636
1637 private boolean hasManagerRole( AgendaResource agenda, HttpServletRequest request )
1638 {
1639 boolean bHasManagerRole = false;
1640 if ( agenda != null )
1641 {
1642 String strManagerRole = agenda.getRoleManager( );
1643
1644 bHasManagerRole = hasRole( strManagerRole, request );
1645 }
1646 return bHasManagerRole;
1647 }
1648
1649
1650
1651
1652
1653
1654
1655 private boolean hasRole( String strRole, HttpServletRequest request )
1656 {
1657 boolean bHasRole = false;
1658
1659 if ( StringUtils.isNotBlank( strRole ) && !Constants.PROPERTY_ROLE_NONE.equals( strRole )
1660 && SecurityService.isAuthenticationEnable( )
1661 && SecurityService.getInstance( ).isUserInRole( request, strRole ) )
1662 {
1663 bHasRole = true;
1664 }
1665
1666 return bHasRole;
1667 }
1668
1669
1670
1671
1672
1673
1674
1675
1676 private LuteceUser getUser( HttpServletRequest request ) throws UserNotSignedException, PageNotFoundException
1677 {
1678 if ( SecurityService.isAuthenticationEnable( ) )
1679 {
1680 LuteceUser user = SecurityService.getInstance( ).getRemoteUser( request );
1681
1682 if ( user == null )
1683 {
1684 throw new UserNotSignedException( );
1685 }
1686
1687 return user;
1688 }
1689 throw new PageNotFoundException( );
1690 }
1691 }