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.helpdesk.web;
35
36 import java.io.IOException;
37 import java.io.InputStreamReader;
38 import java.io.Reader;
39 import java.util.ArrayList;
40 import java.util.Collection;
41 import java.util.Collections;
42 import java.util.Date;
43 import java.util.HashMap;
44 import java.util.List;
45 import java.util.Map;
46
47 import javax.servlet.http.HttpServletRequest;
48
49 import org.apache.commons.fileupload.FileItem;
50
51 import au.com.bytecode.opencsv.CSVReader;
52 import fr.paris.lutece.plugins.helpdesk.business.Faq;
53 import fr.paris.lutece.plugins.helpdesk.business.FaqHome;
54 import fr.paris.lutece.plugins.helpdesk.business.QuestionAnswer;
55 import fr.paris.lutece.plugins.helpdesk.business.QuestionAnswerHome;
56 import fr.paris.lutece.plugins.helpdesk.business.Subject;
57 import fr.paris.lutece.plugins.helpdesk.business.SubjectHome;
58 import fr.paris.lutece.plugins.helpdesk.business.Theme;
59 import fr.paris.lutece.plugins.helpdesk.business.ThemeHome;
60 import fr.paris.lutece.plugins.helpdesk.business.VisitorQuestion;
61 import fr.paris.lutece.plugins.helpdesk.business.VisitorQuestionHome;
62 import fr.paris.lutece.plugins.helpdesk.service.FaqResourceIdService;
63 import fr.paris.lutece.plugins.helpdesk.service.search.HelpdeskIndexer;
64 import fr.paris.lutece.plugins.helpdesk.utils.HelpdeskIndexerUtils;
65 import fr.paris.lutece.portal.business.indexeraction.IndexerAction;
66 import fr.paris.lutece.portal.business.mailinglist.Recipient;
67 import fr.paris.lutece.portal.business.rbac.RBAC;
68 import fr.paris.lutece.portal.business.role.RoleHome;
69 import fr.paris.lutece.portal.business.user.AdminUser;
70 import fr.paris.lutece.portal.business.user.AdminUserHome;
71 import fr.paris.lutece.portal.service.admin.AdminUserService;
72 import fr.paris.lutece.portal.service.i18n.I18nService;
73 import fr.paris.lutece.portal.service.mail.MailService;
74 import fr.paris.lutece.portal.service.mailinglist.AdminMailingListService;
75 import fr.paris.lutece.portal.service.message.AdminMessage;
76 import fr.paris.lutece.portal.service.message.AdminMessageService;
77 import fr.paris.lutece.portal.service.rbac.RBACService;
78 import fr.paris.lutece.portal.service.search.IndexationService;
79 import fr.paris.lutece.portal.service.template.AppTemplateService;
80 import fr.paris.lutece.portal.service.util.AppLogService;
81 import fr.paris.lutece.portal.service.util.AppPathService;
82 import fr.paris.lutece.portal.service.util.AppPropertiesService;
83 import fr.paris.lutece.portal.service.workgroup.AdminWorkgroupService;
84 import fr.paris.lutece.portal.web.admin.PluginAdminPageJspBean;
85 import fr.paris.lutece.portal.web.constants.Messages;
86 import fr.paris.lutece.portal.web.upload.MultipartHttpServletRequest;
87 import fr.paris.lutece.util.ReferenceList;
88 import fr.paris.lutece.util.filesystem.UploadUtil;
89 import fr.paris.lutece.util.html.HtmlTemplate;
90 import fr.paris.lutece.util.html.Paginator;
91 import fr.paris.lutece.util.url.UrlItem;
92
93
94
95
96
97
98 public class HelpdeskJspBean extends PluginAdminPageJspBean
99 {
100
101 public static final String RIGHT_MANAGE_HELPDESK = "HELPDESK_MANAGEMENT";
102
103
104 private static final String JSP_MANAGE_HELPDESK = "ManageHelpdesk.jsp";
105 private static final String JSP_SUBJECTS_LIST = "SubjectsList.jsp";
106 private static final String JSP_QUESTION_ANSWER_LIST = "QuestionAnswerList.jsp";
107 private static final String JSP_VISITOR_QUESTION_LIST = "VisitorQuestionList.jsp";
108 private static final String JSP_CREATE_QUESTION_ANSWER = "CreateQuestionAnswer.jsp";
109 private static final String JSP_ARCHIVED_QUESTION_LIST = "ArchivedQuestionList.jsp";
110 private static final String JSP_MANAGE_HELPDESK_LIST = "ManageHelpdeskAdmin.jsp";
111 private static final String JSP_DO_REMOVE_SUBJECT = "jsp/admin/plugins/helpdesk/DoRemoveSubject.jsp";
112 private static final String JSP_DO_REMOVE_QUESTION_ANSWER = "jsp/admin/plugins/helpdesk/DoRemoveQuestionAnswer.jsp";
113 private static final String JSP_LIST_SUBJECTS = "jsp/admin/plugins/helpdesk/SubjectsList.jsp";
114 private static final String JSP_HELPDESK_MANAGE = "jsp/admin/plugins/helpdesk/ManageHelpdesk.jsp";
115 private static final String JSP_LIST_QUESTIONS_ANSWER = "jsp/admin/plugins/helpdesk/QuestionAnswerList.jsp";
116 private static final String JSP_MANAGE_HELPDESK_ADMIN = "jsp/admin/plugins/helpdesk/ManageHelpdeskAdmin.jsp";
117 private static final String JSP_DO_REMOVE_THEME = "jsp/admin/plugins/helpdesk/DoRemoveTheme.jsp";
118 private static final String JSP_DO_REMOVE_FAQ = "jsp/admin/plugins/helpdesk/DoRemoveFaq.jsp";
119 private static final String JSP_DO_REMOVE_SELECTION = "jsp/admin/plugins/helpdesk/DoRemoveSelection.jsp";
120 private static final String JSP_DO_IMPORT_CSV = "jsp/admin/plugins/helpdesk/DoConfirmImportCSV.jsp";
121
122
123 private static final String PARAMETER_LAST_NAME = "last_name";
124 private static final String PARAMETER_FIRST_NAME = "first_name";
125 private static final String PARAMETER_EMAIL = "email";
126 private static final String PARAMETER_QUESTION = "question";
127 private static final String PARAMETER_QUESTION_ID = "question_id";
128 private static final String PARAMETER_STATUS = "status";
129 private static final String PARAMETER_ANSWER = "answer";
130 private static final String PARAMETER_SUBJECT_ID = "subject_id";
131 private static final String PARAMETER_SUBJECT = "subject";
132 private static final String PARAMETER_MAIL_SUBJECT = "mail_subject";
133 private static final String PARAMETER_PARENT_ID = "parent_id";
134 private static final String PARAMETER_ADD_QUESTION_ANSWER = "add_question_answer";
135 private static final String PARAMETER_CSV_FILE = "csv_file";
136 private static final String PARAMETER_DELETE_LIST = "delete_list";
137 private static final String PARAMETER_THEME = "theme";
138 private static final String PARAMETER_THEME_ID = "theme_id";
139 private static final String PARAMETER_QUESTION_MAILINGLIST = "mailinglists";
140 private static final String PARAMETER_NAME = "name";
141 private static final String PARAMETER_ROLE_KEY = "role_key";
142 private static final String PARAMETER_WORKGROUP_KEY = "workgroup_key";
143 private static final String PARAMETER_DESCRIPTION = "description";
144 private static final String PARAMETER_FAQ_ID = "faq_id";
145 private static final String PARAMETER_CONTENT_HTML = "html_content";
146 private static final String PARAMETER_NB_ITEMS_PER_PAGE = "items_per_page";
147 private static final String PARAMETER_QUESTION_SELECTION = "question_selection";
148 private static final String PARAMETER_SELECTION = "selection";
149
150
151 private static final String TEMPLATE_SUBJECTS = "admin/plugins/helpdesk/subjects.html";
152 private static final String TEMPLATE_MANAGE_HELPDESK = "admin/plugins/helpdesk/manage_helpdesk.html";
153 private static final String TEMPLATE_CREATE_SUBJECT = "admin/plugins/helpdesk/create_subject.html";
154 private static final String TEMPLATE_MODIFY_SUBJECT = "admin/plugins/helpdesk/modify_subject.html";
155 private static final String TEMPLATE_QUESTION_ANSWER_LIST = "admin/plugins/helpdesk/question_answer_list.html";
156 private static final String TEMPLATE_CREATE_QUESTION_ANSWER = "admin/plugins/helpdesk/create_question_answer.html";
157 private static final String TEMPLATE_MODIFY_QUESTION_ANSWER = "admin/plugins/helpdesk/modify_question_answer.html";
158 private static final String TEMPLATE_MODIFY_VISITOR_QUESTION = "admin/plugins/helpdesk/modify_visitor_question.html";
159 private static final String TEMPLATE_ANSWER_SELECTION = "admin/plugins/helpdesk/answer_selection.html";
160 private static final String TEMPLATE_VISITOR_QUESTION_LIST = "admin/plugins/helpdesk/visitor_question_list.html";
161 private static final String TEMPLATE_VIEW_VISITOR_QUESTION = "admin/plugins/helpdesk/view_visitor_question.html";
162 private static final String TEMPLATE_SEND_ANSWER = "admin/plugins/helpdesk/send_answer.html";
163 private static final String TEMPLATE_ARCHIVED_QUESTION_LIST = "admin/plugins/helpdesk/archived_question_list.html";
164 private static final String TEMPLATE_THEME_LIST = "admin/plugins/helpdesk/themes.html";
165 private static final String TEMPLATE_CREATE_THEME = "admin/plugins/helpdesk/create_theme.html";
166 private static final String TEMPLATE_MODIFY_THEME = "admin/plugins/helpdesk/modify_theme.html";
167 private static final String TEMPLATE_CREATE_FAQ = "admin/plugins/helpdesk/create_faq.html";
168 private static final String TEMPLATE_MODIFY_FAQ = "admin/plugins/helpdesk/modify_faq.html";
169 private static final String TEMPLATE_IMPORT_QUESTION_ANSWER_LIST = "admin/plugins/helpdesk/import_question_answer_list.html";
170 private static final String TEMPLATE_SEND_NEW_QUESTION_NOTIFICATION = "admin/plugins/helpdesk/send_notification.html";
171
172
173 private static final String PROPERTY_IMPORT_DELIMITER = "csv.import.delimiter";
174 private static final String PROPERTY_CSV_FILE_EXTENSION = "csv.import.extension";
175 private static final String PROPERTY_CSV_FILE_CHARSET = "csv.import.charset";
176 private static final String PROPERTY_CSV_HEADER = "csv.import.header";
177 private static final String PROPERTY_CSV_COLUMNS_LIST = "csv.import.columns";
178 private static final String PROPERTY_CHECK = "checked";
179 private static final String PROPERTY_NULL = "";
180 private static final String PROPERTY_STYLES_PER_PAGE = "paginator.style.itemsPerPage";
181 private static final String PROPERTY_RESULTS_PER_PAGE = "helpdesk.healpdesksearch.nb.docs.per.page";
182 private static final String PROPERTY_MAIL_SUBJECT_PREFIX = "mail.helpdesk.subjectPrefix";
183
184
185 private static final String MESSAGE_PAGE_TITLE_SUBJECT_LIST = "helpdesk.subjects.pageTitle";
186 private static final String MESSAGE_PAGE_TITLE_FAQ_LIST = "helpdesk.faq.pageTitle";
187 private static final String MESSAGE_PAGE_TITLE_CREATE_SUBJECT = "helpdesk.create_subject.pageTitle";
188 private static final String MESSAGE_PAGE_TITLE_CREATE_FAQ = "helpdesk.create_faq.pageTitle";
189 private static final String MESSAGE_PAGE_TITLE_QUESTION_ANSWER_LIST = "helpdesk.question_answer_list.pageTitle";
190 private static final String MESSAGE_PAGE_TITLE_CREATE_QUESTION_ANSWER = "helpdesk.create_question_answer.pageTitle";
191 private static final String MESSAGE_PAGE_TITLE_MODIFY_QUESTION_ANSWER = "helpdesk.modify_question_answer.pageTitle";
192 private static final String MESSAGE_PAGE_TITLE_MODIFY_VISITOR_QUESTION = "helpdesk.modify_visitor_question.pageTitle";
193 private static final String MESSAGE_PAGE_TITLE_VISITOR_QUESTION_LIST = "helpdesk.visitor_question_list.pageTitle";
194 private static final String MESSAGE_PAGE_TITLE_ARCHIVED_QUESTION_LIST = "helpdesk.archived_question_list.pageTitle";
195 private static final String MESSAGE_PAGE_TITLE_MODIFY_SUBJECT = "helpdesk.modify_subject.pageTitle";
196 private static final String MESSAGE_PORTAL_NAME = "lutece.name";
197 private static final String MESSAGE_MAIL_HELPDESK_SENDER = "mail.helpdesk.sender";
198 private static final String MESSAGE_PAGE_TITLE_CREATE_THEME = "helpdesk.create_theme.pageTitle";
199 private static final String MESSAGE_PAGE_TITLE_MODIFY_THEME = "helpdesk.modify_theme.pageTitle";
200 private static final String MESSAGE_PAGE_TITLE_THEMES = "helpdesk.themes.pageTitle";
201 private static final String MESSAGE_PAGE_TITLE_MODIFY_FAQ = "helpdesk.modify_faq.pageTitle";
202 private static final String MESSAGE_PAGE_TITLE_IMPORT_QUESTION_ANSWER_LIST = "helpdesk.import_question_answer_list.pageTitle";
203 private static final String MESSAGE_CONFIRM_DELETE_SUBJECT = "helpdesk.message.confirmDeleteSubject";
204 private static final String MESSAGE_CANNOT_DELETE_SUBJECT = "helpdesk.message.cannotDeleteSubject";
205 private static final String MESSAGE_CONFIRM_DELETE_QUESTION_ANSWER = "helpdesk.message.confirmDeleteQuestionAnswer";
206 private static final String MESSAGE_CSV_FILE_NOT_VALID = "helpdesk.message.fileNotValid";
207 private static final String MESSAGE_CSV_FIELD_ERROR = "helpdesk.message.fieldError";
208 private static final String MESSAGE_CSV_FILE_EMPTY = "helpdesk.message.fileEmpty";
209 private static final String MESSAGE_CSV_COLUMNS_LIST_ERROR = "helpdesk.message.csvColumnListError";
210 private static final String MESSAGE_IMPORT_CSV_OK = "helpdesk.message.csvImportOk";
211 private static final String MESSAGE_CONFIRM_DELETE_THEME = "helpdesk.message.confirmDeleteTheme";
212 private static final String MESSAGE_CANNOT_DELETE_THEME_QUESTION_EXISTS = "helpdesk.message.cannotDeleteThemeQuestionExists";
213 private static final String MESSAGE_CANNOT_DELETE_THEME_SUB_THEME_EXISTS = "helpdesk.message.cannotDeleteThemeSubThemeExists";
214 private static final String MESSAGE_NO_MAILING_LIST_EXIST_THEME = "helpdesk.message.noMailingListExistTheme";
215 private static final String MESSAGE_CANNOT_DELETE_FAQ = "helpdesk.message.cannotDeleteFaq";
216 private static final String MESSAGE_CONFIRM_DELETE_FAQ = "helpdesk.message.confirmDeleteFaq";
217 private static final String MESSAGE_ACCESS_DENIED = "helpdesk.message.accessDenied";
218 private static final String MESSAGE_NEW_QUESTION = "helpdesk.message.newQuestion";
219 private static final String MESSAGE_CONFIRM_DELETE_SELECTION = "helpdesk.message.confirmDeleteSelection";
220 private static final String MESSAGE_CONFIRM_IMPORT_WITHOUT_DELETING = "helpdesk.message.confirmImportWithoutDeleting";
221
222
223 private static final String MARK_VISITOR_QUESTION = "visitor_question";
224 private static final String MARK_PORTAL_URL = "portal_url";
225 private static final String MARK_ARCHIVED_QUESTION_LIST = "helpdesk_archived_question_list";
226 private static final String MARK_SUBJECT_LIST = "helpdesk_subject_list";
227 private static final String MARK_FAQ_LIST = "helpdesk_faq_list";
228 private static final String MARK_DEFAULT_VALUE = "default_value";
229 private static final String MARK_PLUGIN = "plugin";
230 private static final String MARK_SUBJECT = "subject";
231 private static final String MARK_QUESTION_LIST = "helpdesk_question_list";
232 private static final String MARK_QUESTION_ANSWER = "question_answer";
233 private static final String MARK_CHECKED = "checked";
234 private static final String MARK_ANSWER = "answer";
235 private static final String MARK_QUESTION = "question";
236 private static final String MARK_HELPDESK_USER = "helpdesk_user";
237 private static final String MARK_QUESTION_ANSWER_LIST = "question_answer_list";
238 private static final String MARK_PAGINATOR = "paginator";
239 private static final String MARK_NB_ITEMS_PER_PAGE = "nb_items_per_page";
240 private static final String MARK_WEBAPP_URL = "webapp_url";
241 private static final String MARK_LOCALE = "locale";
242 private static final String MARK_HTML_CONTENT = "html_content";
243 private static final String MARK_THEME = "theme";
244 private static final String MARK_THEME_LIST = "helpdesk_theme_list";
245 private static final String MARK_THEME_ID = "theme_id";
246 private static final String MARK_MAILINGLISTS_LIST = "mailing_list";
247 private static final String MARK_FAQ = "faq";
248 private static final Object MARK_ROLE_KEY_LIST = "role_key_list";
249 private static final Object MARK_DEFAULT_VALUE_ROLE_KEY = "role_key_default_value";
250 private static final Object MARK_DEFAULT_VALUE_WORKGROUP_KEY = "workgroup_key_default_value";
251 private static final Object MARK_WORKGROUP_KEY_LIST = "workgroup_key_list";
252 private static final String MARK_FAQ_ID = "faq_id";
253 private static final String MARK_FAQ_NAME = "faq_name";
254
255
256 private static final String DEFAULT_CSV_FILE_EXTENSION = "csv";
257 private static final String DEFAULT_CSV_FILE_CHARSET = "UTF-8";
258 private static final String DEFAULT_IMPORT_DELIMITER = ";";
259 private static final String DEFAULT_CSV_HEADER = "false";
260 private static final String DEFAULT_CSV_COLUMNS = "subject_id,id_order,question,answer";
261 private static final String DEFAULT_CONSTANT_DELIMITER_COLUMNS_LIST = ",";
262 private static final String DEFAULT_RESULTS_PER_PAGE = "10";
263
264
265 private static final int ROOT_SUBJECT_ID = 0;
266 private static final String REGEX_ID = "^[\\d]+$";
267 private static final String CONSTANT_SPACE = " ";
268 private static final String CONSTANT_MINUS = " - ";
269 private static final String CONSTANT_PUBLISH = "publish";
270 private static final String CONSTANT_UNPUBLISH = "unpublish";
271 private static final String CONSTANT_REMOVE = "remove";
272 private int _nItemsPerPage;
273 private int _nDefaultItemsPerPage;
274 private String _strCurrentPageIndex;
275 private String[] _multiSelectionValues;
276 private FileItem _csvItem;
277
278
279
280
281 public HelpdeskJspBean( )
282 {
283 }
284
285
286
287
288
289
290 public String getSubjectsList( HttpServletRequest request )
291 {
292 Map<String, Object> model = new HashMap<String, Object>( );
293 Faq faq = getAuthorizedFaq( request, FaqResourceIdService.PERMISSION_MANAGE_SUBJECTS );
294
295 if ( faq == null )
296 {
297 return getManageHelpdesk( request );
298 }
299
300 setPageTitleProperty( MESSAGE_PAGE_TITLE_SUBJECT_LIST );
301
302 Collection<Subject> listSubject = (Collection<Subject>) SubjectHome.getInstance( )
303 .findByIdFaq( faq.getId( ), getPlugin( ) );
304 _nDefaultItemsPerPage = AppPropertiesService.getPropertyInt( PROPERTY_STYLES_PER_PAGE, 10 );
305 _strCurrentPageIndex = Paginator.getPageIndex( request, Paginator.PARAMETER_PAGE_INDEX, _strCurrentPageIndex );
306 _nItemsPerPage = Paginator.getItemsPerPage( request, Paginator.PARAMETER_ITEMS_PER_PAGE, _nItemsPerPage,
307 _nDefaultItemsPerPage );
308
309 UrlItem url = new UrlItem( JSP_LIST_SUBJECTS );
310 url.addParameter( PARAMETER_FAQ_ID, faq.getId( ) );
311
312 Paginator paginator = new Paginator( (List<Subject>) listSubject, _nItemsPerPage, url.getUrl( ),
313 Paginator.PARAMETER_PAGE_INDEX, _strCurrentPageIndex );
314
315 model.put( MARK_NB_ITEMS_PER_PAGE, "" + _nItemsPerPage );
316 model.put( MARK_PAGINATOR, paginator );
317 model.put( MARK_SUBJECT_LIST, paginator.getPageItems( ) );
318 model.put( MARK_PLUGIN, getPlugin( ) );
319 model.put( MARK_FAQ, faq );
320
321 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_SUBJECTS, getLocale( ), model );
322
323 return getAdminPage( template.getHtml( ) );
324 }
325
326
327
328
329
330
331 public String getCreateSubject( HttpServletRequest request )
332 {
333 Faq faq = getAuthorizedFaq( request, FaqResourceIdService.PERMISSION_MANAGE_SUBJECTS );
334
335 if ( faq == null )
336 {
337 return getSubjectsList( request );
338 }
339
340 Map<String, Object> model = new HashMap<String, Object>( );
341 setPageTitleProperty( MESSAGE_PAGE_TITLE_CREATE_SUBJECT );
342
343 Collection<Subject> listSubjects = (Collection<Subject>) SubjectHome.getInstance( )
344 .findByIdFaq( faq.getId( ), getPlugin( ) );
345 model.put( MARK_SUBJECT_LIST, listSubjects );
346 model.put( MARK_PLUGIN, getPlugin( ) );
347 model.put( MARK_DEFAULT_VALUE, ROOT_SUBJECT_ID );
348 model.put( MARK_FAQ_ID, request.getParameter( PARAMETER_FAQ_ID ) );
349
350 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_CREATE_SUBJECT, getLocale( ), model );
351
352 return getAdminPage( template.getHtml( ) );
353 }
354
355
356
357
358
359
360 public String doCreateSubject( HttpServletRequest request )
361 {
362 Faq faq = getAuthorizedFaq( request, FaqResourceIdService.PERMISSION_MANAGE_SUBJECTS );
363
364 if ( faq == null )
365 {
366 return AdminMessageService.getMessageUrl( request, MESSAGE_ACCESS_DENIED, AdminMessage.TYPE_STOP );
367 }
368
369 String strSubject = request.getParameter( PARAMETER_SUBJECT );
370 String strParentId = request.getParameter( PARAMETER_PARENT_ID );
371
372
373 if ( ( strSubject == null ) || strSubject.equals( "" ) || ( strParentId == null ) ||
374 !strParentId.matches( REGEX_ID ) )
375 {
376 return AdminMessageService.getMessageUrl( request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP );
377 }
378
379 Subjecthelpdesk/business/Subject.html#Subject">Subject subject = new Subject( );
380 subject.setText( strSubject );
381 subject.setIdParent( Integer.parseInt( strParentId ) );
382 subject = (Subject) SubjectHome.getInstance( ).create( subject, faq.getId( ), getPlugin( ) );
383
384 if ( subject.getIdParent( ) == 0 )
385 {
386 SubjectHome.getInstance( ).createLinkToFaq( subject.getId( ), faq.getId( ), getPlugin( ) );
387 }
388
389
390 UrlItem url = new UrlItem( JSP_SUBJECTS_LIST );
391 url.addParameter( PARAMETER_FAQ_ID, faq.getId( ) );
392
393 return url.getUrl( );
394 }
395
396
397
398
399
400
401 public String doGoDownSubject( HttpServletRequest request )
402 {
403 Faq faq = getAuthorizedFaq( request, FaqResourceIdService.PERMISSION_MANAGE_SUBJECTS );
404
405 if ( faq == null )
406 {
407 return AdminMessageService.getMessageUrl( request, MESSAGE_ACCESS_DENIED, AdminMessage.TYPE_STOP );
408 }
409
410 String strIdSubject = request.getParameter( PARAMETER_SUBJECT_ID );
411 int nIdSubject = Integer.parseInt( strIdSubject );
412 SubjectHome.getInstance( ).goDown( nIdSubject, faq.getId( ), getPlugin( ) );
413
414 UrlItem url = new UrlItem( JSP_SUBJECTS_LIST );
415 url.addParameter( PARAMETER_FAQ_ID, faq.getId( ) );
416
417 return url.getUrl( );
418 }
419
420
421
422
423
424
425 public String doGoUpSubject( HttpServletRequest request )
426 {
427 Faq faq = getAuthorizedFaq( request, FaqResourceIdService.PERMISSION_MANAGE_SUBJECTS );
428
429 if ( faq == null )
430 {
431 return AdminMessageService.getMessageUrl( request, MESSAGE_ACCESS_DENIED, AdminMessage.TYPE_STOP );
432 }
433
434 String strIdSubject = request.getParameter( PARAMETER_SUBJECT_ID );
435 int nIdSubject = Integer.parseInt( strIdSubject );
436 SubjectHome.getInstance( ).goUp( nIdSubject, faq.getId( ), getPlugin( ) );
437
438 UrlItem url = new UrlItem( JSP_SUBJECTS_LIST );
439 url.addParameter( PARAMETER_FAQ_ID, faq.getId( ) );
440
441 return url.getUrl( );
442 }
443
444
445
446
447
448
449 public String doGoInSubject( HttpServletRequest request )
450 {
451 Faq faq = getAuthorizedFaq( request, FaqResourceIdService.PERMISSION_MANAGE_SUBJECTS );
452
453 if ( faq == null )
454 {
455 return AdminMessageService.getMessageUrl( request, MESSAGE_ACCESS_DENIED, AdminMessage.TYPE_STOP );
456 }
457
458 UrlItem url = new UrlItem( JSP_SUBJECTS_LIST );
459 url.addParameter( PARAMETER_FAQ_ID, faq.getId( ) );
460
461 String strIdSubject = request.getParameter( PARAMETER_SUBJECT_ID );
462 int nIdSubject = Integer.parseInt( strIdSubject );
463 Subject/../../../../../fr/paris/lutece/plugins/helpdesk/business/Subject.html#Subject">Subject subject = (Subject) SubjectHome.getInstance( ).findByPrimaryKey( nIdSubject, getPlugin( ) );
464
465 if ( subject == null )
466 {
467 return url.getUrl( );
468 }
469
470 if ( subject.getIdParent( ) == 0 )
471 {
472 SubjectHome.getInstance( ).removeLinkToFaq( nIdSubject, faq.getId( ), getPlugin( ) );
473 }
474
475 SubjectHome.getInstance( ).goIn( nIdSubject, faq.getId( ), getPlugin( ) );
476
477 return url.getUrl( );
478 }
479
480
481
482
483
484
485 public String doGoOutSubject( HttpServletRequest request )
486 {
487 Faq faq = getAuthorizedFaq( request, FaqResourceIdService.PERMISSION_MANAGE_SUBJECTS );
488
489 if ( faq == null )
490 {
491 return AdminMessageService.getMessageUrl( request, MESSAGE_ACCESS_DENIED, AdminMessage.TYPE_STOP );
492 }
493
494 UrlItem url = new UrlItem( JSP_SUBJECTS_LIST );
495 url.addParameter( PARAMETER_FAQ_ID, faq.getId( ) );
496
497 String strIdSubject = request.getParameter( PARAMETER_SUBJECT_ID );
498 int nIdSubject = Integer.parseInt( strIdSubject );
499 SubjectHome.getInstance( ).goOut( nIdSubject, faq.getId( ), getPlugin( ) );
500
501 Subject/../../../../../fr/paris/lutece/plugins/helpdesk/business/Subject.html#Subject">Subject subject = (Subject) SubjectHome.getInstance( ).findByPrimaryKey( nIdSubject, getPlugin( ) );
502
503 if ( subject == null )
504 {
505 return url.getUrl( );
506 }
507
508 if ( subject.getIdParent( ) == 0 )
509 {
510 SubjectHome.getInstance( ).removeLinkToFaq( nIdSubject, faq.getId( ), getPlugin( ) );
511 SubjectHome.getInstance( ).createLinkToFaq( nIdSubject, faq.getId( ), getPlugin( ) );
512 }
513
514 return url.getUrl( );
515 }
516
517
518
519
520
521
522 public String getModifySubject( HttpServletRequest request )
523 {
524 Faq faq = getAuthorizedFaq( request, FaqResourceIdService.PERMISSION_MANAGE_SUBJECTS );
525
526 if ( faq == null )
527 {
528 return getSubjectsList( request );
529 }
530
531 HashMap model = new HashMap( );
532
533 setPageTitleProperty( MESSAGE_PAGE_TITLE_MODIFY_SUBJECT );
534
535 String strIdSubject = request.getParameter( PARAMETER_SUBJECT_ID );
536
537 int nIdSubject = Integer.parseInt( strIdSubject );
538 Subject/../../../../../fr/paris/lutece/plugins/helpdesk/business/Subject.html#Subject">Subject subject = (Subject) SubjectHome.getInstance( ).findByPrimaryKey( nIdSubject, getPlugin( ) );
539
540 if ( subject == null )
541 {
542 return getSubjectsList( request );
543 }
544
545 model.put( MARK_SUBJECT, subject );
546 model.put( MARK_PLUGIN, getPlugin( ) );
547 model.put( MARK_FAQ_ID, faq.getId( ) );
548
549 Collection<Subject> listSubjects = (Collection<Subject>) SubjectHome.getInstance( )
550 .findByIdFaq( faq.getId( ), getPlugin( ) );
551 model.put( MARK_SUBJECT_LIST, listSubjects );
552
553 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MODIFY_SUBJECT, getLocale( ), model );
554
555 return getAdminPage( template.getHtml( ) );
556 }
557
558
559
560
561
562
563 public String doModifySubject( HttpServletRequest request )
564 {
565 Faq faq = getAuthorizedFaq( request, FaqResourceIdService.PERMISSION_MANAGE_SUBJECTS );
566
567 if ( faq == null )
568 {
569 return AdminMessageService.getMessageUrl( request, MESSAGE_ACCESS_DENIED, AdminMessage.TYPE_STOP );
570 }
571
572 String strSubject = request.getParameter( PARAMETER_SUBJECT );
573 String strIdSubject = request.getParameter( PARAMETER_SUBJECT_ID );
574 String strIdParent = request.getParameter( PARAMETER_PARENT_ID );
575
576
577 if ( request.getParameter( PARAMETER_SUBJECT ).equals( "" ) || ( strIdParent == null ) ||
578 !strIdParent.matches( REGEX_ID ) )
579 {
580 return AdminMessageService.getMessageUrl( request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP );
581 }
582
583 int nIdSubject = Integer.parseInt( strIdSubject );
584 int nIdParent = Integer.parseInt( strIdParent );
585
586
587 Subject/../../../../../fr/paris/lutece/plugins/helpdesk/business/Subject.html#Subject">Subject subject = (Subject) SubjectHome.getInstance( ).findByPrimaryKey( nIdSubject, getPlugin( ) );
588 subject.setText( strSubject );
589
590
591 if ( nIdParent != subject.getIdParent( ) )
592 {
593 if ( subject.getIdParent( ) == 0 )
594 {
595 SubjectHome.getInstance( ).removeLinkToFaq( nIdSubject, faq.getId( ), getPlugin( ) );
596 }
597
598 if ( nIdParent == 0 )
599 {
600 SubjectHome.getInstance( ).createLinkToFaq( nIdSubject, faq.getId( ), getPlugin( ) );
601 }
602
603 subject.setIdParent( nIdParent );
604 subject.setIdOrder( SubjectHome.FIRST_ORDER );
605 }
606
607 SubjectHome.getInstance( ).update( subject, faq.getId( ), getPlugin( ) );
608
609
610 UrlItem url = new UrlItem( JSP_SUBJECTS_LIST );
611 url.addParameter( PARAMETER_FAQ_ID, faq.getId( ) );
612
613 return url.getUrl( );
614 }
615
616
617
618
619
620
621 public String getConfirmRemoveSubject( HttpServletRequest request )
622 {
623 Faq faq = getAuthorizedFaq( request, FaqResourceIdService.PERMISSION_MANAGE_SUBJECTS );
624
625 if ( faq == null )
626 {
627 return AdminMessageService.getMessageUrl( request, MESSAGE_ACCESS_DENIED, AdminMessage.TYPE_STOP );
628 }
629
630 int nIdSubject = Integer.parseInt( request.getParameter( PARAMETER_SUBJECT_ID ) );
631
632 UrlItem url = new UrlItem( JSP_DO_REMOVE_SUBJECT );
633 url.addParameter( PARAMETER_SUBJECT_ID, nIdSubject );
634 url.addParameter( PARAMETER_FAQ_ID, faq.getId( ) );
635
636 Subject/../../../../../fr/paris/lutece/plugins/helpdesk/business/Subject.html#Subject">Subject subject = (Subject) SubjectHome.getInstance( ).findByPrimaryKey( nIdSubject, getPlugin( ) );
637
638 if ( ( subject == null ) || ( subject.getChilds( getPlugin( ) ).size( ) > 0 ) )
639 {
640 return AdminMessageService.getMessageUrl( request, MESSAGE_CANNOT_DELETE_SUBJECT, AdminMessage.TYPE_STOP );
641 }
642
643 return AdminMessageService.getMessageUrl( request, MESSAGE_CONFIRM_DELETE_SUBJECT, url.getUrl( ),
644 AdminMessage.TYPE_CONFIRMATION );
645 }
646
647
648
649
650
651
652 public String doRemoveSubject( HttpServletRequest request )
653 {
654 Faq faq = getAuthorizedFaq( request, FaqResourceIdService.PERMISSION_MANAGE_SUBJECTS );
655
656 if ( faq == null )
657 {
658 return AdminMessageService.getMessageUrl( request, MESSAGE_ACCESS_DENIED, AdminMessage.TYPE_STOP );
659 }
660
661 int nIdSubject = Integer.parseInt( request.getParameter( PARAMETER_SUBJECT_ID ) );
662
663 if ( QuestionAnswerHome.countbySubject( nIdSubject, getPlugin( ) ) > 0 )
664 {
665 QuestionAnswerHome.removeBySubject( nIdSubject, getPlugin( ) );
666 }
667
668 Subject/../../../../../fr/paris/lutece/plugins/helpdesk/business/Subject.html#Subject">Subject subject = (Subject) SubjectHome.getInstance( ).findByPrimaryKey( nIdSubject, getPlugin( ) );
669
670 UrlItem url = new UrlItem( JSP_SUBJECTS_LIST );
671 url.addParameter( PARAMETER_SUBJECT_ID, nIdSubject );
672 url.addParameter( PARAMETER_FAQ_ID, faq.getId( ) );
673
674
675 if ( ( subject == null ) || ( subject.getChilds( getPlugin( ) ).size( ) > 0 ) )
676 {
677 return url.getUrl( );
678 }
679
680 if ( subject.getIdParent( ) == 0 )
681 {
682 SubjectHome.getInstance( ).removeLinkToFaq( subject.getId( ), faq.getId( ), getPlugin( ) );
683 }
684
685 SubjectHome.getInstance( ).remove( nIdSubject, faq.getId( ), getPlugin( ) );
686
687
688 return url.getUrl( );
689 }
690
691
692
693
694
695
696 public String getQuestionAnswerList( HttpServletRequest request )
697 {
698 Faq faq = getAuthorizedFaq( request, FaqResourceIdService.PERMISSION_MANAGE_QUESTIONS_ANSWERS );
699
700 if ( faq == null )
701 {
702 return getManageHelpdesk( request );
703 }
704
705 HashMap model = new HashMap( );
706
707 String strIdSubject = request.getParameter( PARAMETER_SUBJECT_ID );
708 Subject subject = null;
709
710 if ( ( strIdSubject != null ) && strIdSubject.matches( REGEX_ID ) )
711 {
712 int nIdSubject = Integer.parseInt( strIdSubject );
713 subject = (Subject) SubjectHome.getInstance( ).findByPrimaryKey( nIdSubject, getPlugin( ) );
714 }
715
716 setPageTitleProperty( MESSAGE_PAGE_TITLE_QUESTION_ANSWER_LIST );
717
718 Collection<Subject> listSubject = (Collection<Subject>) SubjectHome.getInstance( )
719 .findByIdFaq( faq.getId( ), getPlugin( ) );
720
721 if ( ( subject == null ) && ( listSubject.size( ) > 0 ) )
722 {
723 subject = listSubject.iterator( ).next( );
724 }
725
726 String strNbItemPerPage = request.getParameter( PARAMETER_NB_ITEMS_PER_PAGE );
727 String strDefaultNbItemPerPage = AppPropertiesService.getProperty( PROPERTY_RESULTS_PER_PAGE,
728 DEFAULT_RESULTS_PER_PAGE );
729 strNbItemPerPage = ( strNbItemPerPage != null ) ? strNbItemPerPage : strDefaultNbItemPerPage;
730
731 model.put( MARK_SUBJECT_LIST, listSubject );
732 model.put( MARK_PLUGIN, getPlugin( ) );
733 model.put( MARK_SUBJECT, subject );
734 model.put( MARK_FAQ, faq );
735 model.put( MARK_NB_ITEMS_PER_PAGE, strNbItemPerPage );
736 model.put( MARK_LOCALE, request.getLocale( ) );
737
738 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_QUESTION_ANSWER_LIST, getLocale( ), model );
739
740 return getAdminPage( template.getHtml( ) );
741 }
742
743
744
745
746
747
748 public String doGoDownQuestion( HttpServletRequest request )
749 {
750 Faq faq = getAuthorizedFaq( request, FaqResourceIdService.PERMISSION_MANAGE_SUBJECTS );
751
752 if ( faq == null )
753 {
754 return AdminMessageService.getMessageUrl( request, MESSAGE_ACCESS_DENIED, AdminMessage.TYPE_STOP );
755 }
756
757 String strIdQuestion = request.getParameter( PARAMETER_QUESTION_ID );
758 int nIdQuestion = Integer.parseInt( strIdQuestion );
759 QuestionAnswerHome.goDown( nIdQuestion, getPlugin( ) );
760
761 QuestionAnswer questionAnswer = QuestionAnswerHome.findByPrimaryKey(nIdQuestion, getPlugin( ) );
762
763 UrlItem url = new UrlItem( JSP_QUESTION_ANSWER_LIST );
764 url.addParameter( PARAMETER_FAQ_ID, faq.getId( ) );
765 url.addParameter( PARAMETER_SUBJECT_ID, questionAnswer.getIdSubject( ) );
766
767 return url.getUrl( );
768 }
769
770
771
772
773
774
775 public String doGoUpQuestion( HttpServletRequest request )
776 {
777 Faq faq = getAuthorizedFaq( request, FaqResourceIdService.PERMISSION_MANAGE_SUBJECTS );
778
779 if ( faq == null )
780 {
781 return AdminMessageService.getMessageUrl( request, MESSAGE_ACCESS_DENIED, AdminMessage.TYPE_STOP );
782 }
783
784 String strIdQuestion = request.getParameter( PARAMETER_QUESTION_ID );
785 int nIdQuestion = Integer.parseInt( strIdQuestion );
786 QuestionAnswerHome.goUp( nIdQuestion, getPlugin( ) );
787
788 QuestionAnswer questionAnswer = QuestionAnswerHome.findByPrimaryKey(nIdQuestion, getPlugin( ) );
789
790 UrlItem url = new UrlItem( JSP_QUESTION_ANSWER_LIST );
791 url.addParameter( PARAMETER_FAQ_ID, faq.getId( ) );
792 url.addParameter( PARAMETER_SUBJECT_ID, questionAnswer.getIdSubject( ) );
793
794 return url.getUrl( );
795 }
796
797
798
799
800
801
802 public String getCreateQuestionAnswer( HttpServletRequest request )
803 {
804 Faq faq = getAuthorizedFaq( request, FaqResourceIdService.PERMISSION_MANAGE_QUESTIONS_ANSWERS );
805
806 if ( faq == null )
807 {
808 return getQuestionAnswerList( request );
809 }
810
811 HashMap<String, Object> model = new HashMap<String, Object>( );
812 setPageTitleProperty( MESSAGE_PAGE_TITLE_CREATE_QUESTION_ANSWER );
813
814 String strSubjectId = request.getParameter( PARAMETER_SUBJECT_ID );
815 String strIdQuestion = request.getParameter( PARAMETER_QUESTION_ID );
816 String strIdTheme = request.getParameter( PARAMETER_THEME_ID );
817
818 model.put( MARK_SUBJECT_LIST,
819 (Collection<Subject>) SubjectHome.getInstance( ).findByIdFaq( faq.getId( ), getPlugin( ) ) );
820 model.put( MARK_DEFAULT_VALUE, ( strSubjectId == null ) ? "" : strSubjectId );
821 model.put( MARK_PLUGIN, getPlugin( ) );
822 model.put( MARK_WEBAPP_URL, AppPathService.getBaseUrl( request ) );
823 model.put( MARK_LOCALE, AdminUserService.getLocale( request ).getLanguage( ) );
824 model.put( MARK_FAQ_ID, faq.getId( ) );
825 model.put( MARK_FAQ_NAME, faq.getName( ) );
826 model.put( MARK_THEME_ID, strIdTheme);
827
828 if ( strIdQuestion == null )
829 {
830 model.put( MARK_QUESTION, "" );
831 model.put( MARK_HTML_CONTENT, "" );
832 }
833 else
834 {
835 VisitorQuestion visitorQuestion = VisitorQuestionHome.findByPrimaryKey( Integer.parseInt( strIdQuestion ),
836 getPlugin( ) );
837 model.put( MARK_QUESTION, visitorQuestion.getQuestion( ) );
838 model.put( MARK_HTML_CONTENT, visitorQuestion.getAnswer( ) );
839 }
840
841 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_CREATE_QUESTION_ANSWER, getLocale( ), model );
842
843 return getAdminPage( template.getHtml( ) );
844 }
845
846
847
848
849
850
851 public String doCreateQuestionAnswer( HttpServletRequest request )
852 {
853 Faq faq = getAuthorizedFaq( request, FaqResourceIdService.PERMISSION_MANAGE_QUESTIONS_ANSWERS );
854 HashMap<String, Object> model = new HashMap<String, Object>( );
855 if ( faq == null )
856 {
857 return AdminMessageService.getMessageUrl( request, MESSAGE_ACCESS_DENIED, AdminMessage.TYPE_STOP );
858 }
859
860 String strIdSubject = request.getParameter( PARAMETER_SUBJECT_ID );
861 String strQuestion = request.getParameter( PARAMETER_QUESTION );
862 String strAnswer = request.getParameter( PARAMETER_CONTENT_HTML );
863 String strStatus = request.getParameter( PARAMETER_STATUS );
864 String strThemeId = request.getParameter( PARAMETER_THEME_ID );
865 int nStatus = 0;
866
867 if ( strStatus != null )
868 {
869 nStatus = Integer.parseInt( strStatus );
870 }
871
872
873 if ( ( strIdSubject == null ) || ( strQuestion == null ) || ( strAnswer == null ) || strIdSubject.equals( "" ) ||
874 strQuestion.equals( "" ) || strAnswer.equals( "" ) )
875 {
876 return AdminMessageService.getMessageUrl( request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP );
877 }
878
879 int nIdSubject = Integer.parseInt( strIdSubject );
880 QuestionAnsweress/QuestionAnswer.html#QuestionAnswer">QuestionAnswer questionAnswer = new QuestionAnswer( );
881 questionAnswer.setIdSubject( nIdSubject );
882 questionAnswer.setQuestion( strQuestion );
883 questionAnswer.setAnswer( strAnswer );
884 questionAnswer.setStatus( nStatus );
885 questionAnswer.setCreationDate( new Date( ) );
886
887 QuestionAnswerHome.create( questionAnswer, getPlugin( ) );
888
889 if( strThemeId != null )
890 {
891
892 Subject subject = ( Subject ) SubjectHome.getInstance( ).findByPrimaryKey(nIdSubject, getPlugin( ) );
893 int nIdTheme = Integer.parseInt( strThemeId );
894 Theme="../../../../../../fr/paris/lutece/plugins/helpdesk/business/Theme.html#Theme">Theme theme = (Theme) ThemeHome.getInstance( ).findByPrimaryKey( nIdTheme, getPlugin( ) );
895
896 Collection<Recipient> listRecipientTheme = AdminMailingListService.getRecipients( theme.getIdMailingList( ) );
897
898 String strPortal = AppPropertiesService.getProperty( MESSAGE_PORTAL_NAME );
899 String strEmailSender = AppPropertiesService.getProperty( MESSAGE_MAIL_HELPDESK_SENDER );
900 String strSubject = AppPropertiesService.getProperty( PROPERTY_MAIL_SUBJECT_PREFIX )
901 + CONSTANT_SPACE + strPortal + CONSTANT_MINUS
902 + I18nService.getLocalizedString( MESSAGE_NEW_QUESTION, request.getLocale( ) );
903
904
905 model.put( MARK_QUESTION, strQuestion );
906 model.put( MARK_ANSWER, strAnswer );
907 model.put( MARK_SUBJECT, subject.getText( ) );
908
909 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_SEND_NEW_QUESTION_NOTIFICATION, request.getLocale( ),
910 model );
911 String strMessage = template.getHtml( );
912 for ( Recipient recipientUser : listRecipientTheme )
913 {
914 String strEmailWebmaster = recipientUser.getEmail( );
915 MailService.sendMailHtml( strEmailWebmaster, strPortal, strEmailSender, strSubject, strMessage );
916 }
917 }
918
919
920 UrlItem url = new UrlItem( JSP_QUESTION_ANSWER_LIST );
921 url.addParameter( PARAMETER_FAQ_ID, faq.getId( ) );
922 url.addParameter( PARAMETER_SUBJECT_ID, questionAnswer.getIdSubject( ) );
923
924 return url.getUrl( );
925 }
926
927
928
929
930
931
932
933 public String getModifyQuestionAnswer( HttpServletRequest request )
934 {
935 Faq faq = getAuthorizedFaq( request, FaqResourceIdService.PERMISSION_MANAGE_QUESTIONS_ANSWERS );
936
937 if ( faq == null )
938 {
939 return getQuestionAnswerList( request );
940 }
941
942 HashMap model = new HashMap( );
943 setPageTitleProperty( MESSAGE_PAGE_TITLE_MODIFY_QUESTION_ANSWER );
944
945 int nIdQuestionAnswer = Integer.parseInt( request.getParameter( PARAMETER_QUESTION_ID ) );
946
947 QuestionAnswer questionAnswer = QuestionAnswerHome.findByPrimaryKey( nIdQuestionAnswer, getPlugin( ) );
948
949 model.put( MARK_WEBAPP_URL, AppPathService.getBaseUrl( request ) );
950 model.put( MARK_LOCALE, AdminUserService.getLocale( request ).getLanguage( ) );
951 model.put( MARK_HTML_CONTENT, questionAnswer.getAnswer( ) );
952 model.put( MARK_FAQ_ID, faq.getId( ) );
953 model.put( MARK_FAQ_NAME, faq.getName( ) );
954 model.put( MARK_SUBJECT_LIST,
955 (Collection<Subject>) SubjectHome.getInstance( ).findByIdFaq( faq.getId( ), getPlugin( ) ) );
956 model.put( MARK_PLUGIN, getPlugin( ) );
957
958 questionAnswer.setAnswer( questionAnswer.getAnswer( ) );
959
960 if ( questionAnswer.isEnabled( ) )
961 {
962 model.put( MARK_CHECKED, PROPERTY_CHECK );
963 }
964 else
965 {
966 model.put( MARK_CHECKED, PROPERTY_NULL );
967 }
968
969 model.put( MARK_QUESTION_ANSWER, questionAnswer );
970
971 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MODIFY_QUESTION_ANSWER, getLocale( ), model );
972
973 return getAdminPage( template.getHtml( ) );
974 }
975
976
977
978
979
980
981 public String doModifyQuestionAnswer( HttpServletRequest request )
982 {
983 Faq faq = getAuthorizedFaq( request, FaqResourceIdService.PERMISSION_MANAGE_QUESTIONS_ANSWERS );
984
985 if ( faq == null )
986 {
987 return AdminMessageService.getMessageUrl( request, MESSAGE_ACCESS_DENIED, AdminMessage.TYPE_STOP );
988 }
989
990 int nIdQuestionAnswer = Integer.parseInt( request.getParameter( PARAMETER_QUESTION_ID ) );
991 int nIdSubject = Integer.parseInt( request.getParameter( PARAMETER_SUBJECT_ID ) );
992 String strQuestion = request.getParameter( PARAMETER_QUESTION );
993 String strAnswer = request.getParameter( PARAMETER_CONTENT_HTML );
994
995 int nStatus = 0;
996
997 if ( request.getParameter( PARAMETER_STATUS ) != null )
998 {
999 nStatus = 1;
1000 }
1001
1002 QuestionAnswer questionAnswer = QuestionAnswerHome.findByPrimaryKey(nIdQuestionAnswer, getPlugin( ));
1003 if( questionAnswer.getIdSubject( ) != nIdSubject )
1004 {
1005 questionAnswer.setIdOrder( QuestionAnswerHome.FIRST_ORDER );
1006 questionAnswer.setIdSubject( nIdSubject );
1007 }
1008 questionAnswer.setQuestion( strQuestion );
1009 questionAnswer.setAnswer( strAnswer );
1010 questionAnswer.setStatus( nStatus );
1011 questionAnswer.setCreationDate( new Date( ) );
1012
1013
1014 if ( request.getParameter( PARAMETER_SUBJECT_ID ).equals( "" ) ||
1015 request.getParameter( ( PARAMETER_QUESTION ) ).equals( "" ) ||
1016 request.getParameter( PARAMETER_CONTENT_HTML ).equals( "" ) )
1017 {
1018 return AdminMessageService.getMessageUrl( request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP );
1019 }
1020
1021 QuestionAnswerHome.update( questionAnswer, getPlugin( ) );
1022
1023
1024 UrlItem url = new UrlItem( JSP_QUESTION_ANSWER_LIST );
1025 url.addParameter( PARAMETER_FAQ_ID, faq.getId( ) );
1026 url.addParameter( PARAMETER_SUBJECT_ID, questionAnswer.getIdSubject( ) );
1027
1028 return url.getUrl( );
1029 }
1030
1031
1032
1033
1034
1035 public String doActionSelectionQuestionAnswer( HttpServletRequest request )
1036 {
1037 Faq faq = getAuthorizedFaq( request, FaqResourceIdService.PERMISSION_MANAGE_QUESTIONS_ANSWERS );
1038
1039 if ( faq == null )
1040 {
1041 return AdminMessageService.getMessageUrl( request, MESSAGE_ACCESS_DENIED, AdminMessage.TYPE_STOP );
1042 }
1043 String strAction = request.getParameter( PARAMETER_SELECTION );
1044 String[] strIdQuestionAnswers = (String[]) request.getParameterMap( ).get( PARAMETER_QUESTION_SELECTION );
1045 _multiSelectionValues = strIdQuestionAnswers;
1046 String strIdSubject = request.getParameter( PARAMETER_SUBJECT_ID );
1047
1048 if ( strIdQuestionAnswers != null && strIdQuestionAnswers.length > 0 )
1049 {
1050 if( strAction.equals( CONSTANT_REMOVE ) )
1051 {
1052
1053 UrlItem url = new UrlItem( JSP_DO_REMOVE_SELECTION );
1054
1055 url.addParameter( PARAMETER_SUBJECT_ID, strIdSubject );
1056 url.addParameter( PARAMETER_FAQ_ID, faq.getId( ) );
1057
1058 return AdminMessageService.getMessageUrl( request, MESSAGE_CONFIRM_DELETE_SELECTION, url.getUrl( ),
1059 AdminMessage.TYPE_CONFIRMATION );
1060 }
1061
1062 for( String strIdQuestionAnswer : strIdQuestionAnswers )
1063 {
1064 int nIdQuestionAnswer = Integer.parseInt( strIdQuestionAnswer );
1065
1066 QuestionAnswer questionAnswer = QuestionAnswerHome.findByPrimaryKey( nIdQuestionAnswer, getPlugin( ) );
1067
1068 if ( questionAnswer != null )
1069 {
1070 if( ( strAction.equals( CONSTANT_PUBLISH ) ) && ( ! questionAnswer.isEnabled( ) ) )
1071 {
1072 questionAnswer.setStatus( QuestionAnswer.STATUS_PUBLISHED );
1073 QuestionAnswerHome.update( questionAnswer, getPlugin( ) );
1074 }
1075 else if( ( strAction.equals( CONSTANT_UNPUBLISH ) ) && ( questionAnswer.isEnabled( ) ) )
1076 {
1077 questionAnswer.setStatus( QuestionAnswer.STATUS_UNPUBLISHED );
1078 QuestionAnswerHome.update( questionAnswer, getPlugin( ) );
1079 }
1080
1081 }
1082 }
1083 }
1084
1085
1086 UrlItem url = new UrlItem( JSP_QUESTION_ANSWER_LIST );
1087 url.addParameter( PARAMETER_FAQ_ID, faq.getId( ) );
1088 if ( strIdSubject != null )
1089 {
1090 url.addParameter( PARAMETER_SUBJECT_ID, strIdSubject );
1091 }
1092
1093
1094
1095
1096
1097 return url.getUrl( );
1098 }
1099
1100
1101
1102
1103
1104 public String doPublishQuestionAnswer( HttpServletRequest request )
1105 {
1106 Faq faq = getAuthorizedFaq( request, FaqResourceIdService.PERMISSION_MANAGE_QUESTIONS_ANSWERS );
1107
1108 if ( faq == null )
1109 {
1110 return AdminMessageService.getMessageUrl( request, MESSAGE_ACCESS_DENIED, AdminMessage.TYPE_STOP );
1111 }
1112
1113 int nIdQuestionAnswer = Integer.parseInt( request.getParameter( PARAMETER_QUESTION_ID ) );
1114
1115 QuestionAnswer questionAnswer = QuestionAnswerHome.findByPrimaryKey( nIdQuestionAnswer, getPlugin( ) );
1116
1117 if ( questionAnswer != null )
1118 {
1119 questionAnswer.setStatus( QuestionAnswer.STATUS_PUBLISHED );
1120 QuestionAnswerHome.update( questionAnswer, getPlugin( ) );
1121 }
1122
1123
1124 UrlItem url = new UrlItem( JSP_QUESTION_ANSWER_LIST );
1125 url.addParameter( PARAMETER_FAQ_ID, faq.getId( ) );
1126 url.addParameter( PARAMETER_SUBJECT_ID, questionAnswer.getIdSubject( ) );
1127
1128
1129 IndexationService.addIndexerAction( Integer.toString( questionAnswer.getIdSubject( ) ),
1130 AppPropertiesService.getProperty( HelpdeskIndexer.PROPERTY_INDEXER_NAME ), IndexerAction.TASK_MODIFY );
1131
1132 HelpdeskIndexerUtils.addIndexerAction( Integer.toString( questionAnswer.getIdSubject( ) ), IndexerAction.TASK_MODIFY, HelpdeskIndexerUtils.CONSTANT_SUBJECT_TYPE_RESOURCE );
1133
1134 return url.getUrl( );
1135 }
1136
1137
1138
1139
1140
1141
1142 public String doUnpublishQuestionAnswer( HttpServletRequest request )
1143 {
1144 Faq faq = getAuthorizedFaq( request, FaqResourceIdService.PERMISSION_MANAGE_QUESTIONS_ANSWERS );
1145
1146 if ( faq == null )
1147 {
1148 return AdminMessageService.getMessageUrl( request, MESSAGE_ACCESS_DENIED, AdminMessage.TYPE_STOP );
1149 }
1150
1151 int nIdQuestionAnswer = Integer.parseInt( request.getParameter( PARAMETER_QUESTION_ID ) );
1152
1153 QuestionAnswer questionAnswer = QuestionAnswerHome.findByPrimaryKey( nIdQuestionAnswer, getPlugin( ) );
1154
1155 if ( questionAnswer != null )
1156 {
1157 questionAnswer.setStatus( QuestionAnswer.STATUS_UNPUBLISHED );
1158 QuestionAnswerHome.update( questionAnswer, getPlugin( ) );
1159 }
1160
1161
1162 UrlItem url = new UrlItem( JSP_QUESTION_ANSWER_LIST );
1163 url.addParameter( PARAMETER_FAQ_ID, faq.getId( ) );
1164 url.addParameter( PARAMETER_SUBJECT_ID, questionAnswer.getIdSubject( ) );
1165
1166
1167 String strIdQuestionAnswer = Integer.toString( questionAnswer.getIdQuestionAnswer( ) );
1168 IndexationService.addIndexerAction( strIdQuestionAnswer + "_" +
1169 HelpdeskIndexer.SHORT_NAME_QUESTION_ANSWER,
1170 AppPropertiesService.getProperty( HelpdeskIndexer.PROPERTY_INDEXER_NAME ), IndexerAction.TASK_DELETE );
1171
1172 HelpdeskIndexerUtils.addIndexerAction( strIdQuestionAnswer, IndexerAction.TASK_DELETE, HelpdeskIndexerUtils.CONSTANT_QUESTION_ANSWER_TYPE_RESOURCE );
1173
1174 return url.getUrl( );
1175 }
1176
1177
1178
1179
1180
1181
1182 public String getConfirmRemoveQuestionAnswer( HttpServletRequest request )
1183 {
1184 Faq faq = getAuthorizedFaq( request, FaqResourceIdService.PERMISSION_MANAGE_QUESTIONS_ANSWERS );
1185
1186 if ( faq == null )
1187 {
1188 return AdminMessageService.getMessageUrl( request, MESSAGE_ACCESS_DENIED, AdminMessage.TYPE_STOP );
1189 }
1190
1191 int strIdQuestionAnswer = Integer.parseInt( request.getParameter( PARAMETER_QUESTION_ID ) );
1192
1193 UrlItem url = new UrlItem( JSP_DO_REMOVE_QUESTION_ANSWER );
1194 url.addParameter( PARAMETER_QUESTION_ID, strIdQuestionAnswer );
1195 url.addParameter( PARAMETER_SUBJECT_ID, request.getParameter( PARAMETER_SUBJECT_ID ) );
1196 url.addParameter( PARAMETER_FAQ_ID, faq.getId( ) );
1197
1198 return AdminMessageService.getMessageUrl( request, MESSAGE_CONFIRM_DELETE_QUESTION_ANSWER, url.getUrl( ),
1199 AdminMessage.TYPE_CONFIRMATION );
1200 }
1201
1202
1203
1204
1205
1206
1207 public String doRemoveQuestionAnswer( HttpServletRequest request )
1208 {
1209 Faq faq = getAuthorizedFaq( request, FaqResourceIdService.PERMISSION_MANAGE_QUESTIONS_ANSWERS );
1210
1211 if ( faq == null )
1212 {
1213 return AdminMessageService.getMessageUrl( request, MESSAGE_ACCESS_DENIED, AdminMessage.TYPE_STOP );
1214 }
1215
1216 String strIdQuestionAnswer = request.getParameter( PARAMETER_QUESTION_ID );
1217 int nIdQuestionAnswer = Integer.parseInt( strIdQuestionAnswer );
1218 QuestionAnswerHome.remove( nIdQuestionAnswer, getPlugin( ) );
1219
1220
1221 UrlItem url = new UrlItem( JSP_QUESTION_ANSWER_LIST );
1222 url.addParameter( PARAMETER_SUBJECT_ID, request.getParameter( PARAMETER_SUBJECT_ID ) );
1223 url.addParameter( PARAMETER_FAQ_ID, faq.getId( ) );
1224
1225 return url.getUrl( );
1226 }
1227
1228
1229
1230
1231
1232
1233 public String doRemoveSelection( HttpServletRequest request )
1234 {
1235 Faq faq = getAuthorizedFaq( request, FaqResourceIdService.PERMISSION_MANAGE_QUESTIONS_ANSWERS );
1236
1237 if ( faq == null )
1238 {
1239 return AdminMessageService.getMessageUrl( request, MESSAGE_ACCESS_DENIED, AdminMessage.TYPE_STOP );
1240 }
1241
1242 if( _multiSelectionValues != null )
1243 {
1244 for( String strIdQuestionAnswer : _multiSelectionValues)
1245 {
1246 int nIdQuestionAnswer = Integer.parseInt( strIdQuestionAnswer );
1247 QuestionAnswerHome.remove( nIdQuestionAnswer, getPlugin( ) );
1248 }
1249
1250 }
1251
1252
1253 UrlItem url = new UrlItem( JSP_QUESTION_ANSWER_LIST );
1254 url.addParameter( PARAMETER_SUBJECT_ID, request.getParameter( PARAMETER_SUBJECT_ID ) );
1255 url.addParameter( PARAMETER_FAQ_ID, faq.getId( ) );
1256
1257 return url.getUrl( );
1258 }
1259
1260
1261
1262
1263
1264
1265 public String getModifyVisitorQuestion( HttpServletRequest request )
1266 {
1267 Faq faq = getAuthorizedFaq( request, FaqResourceIdService.PERMISSION_MANAGE_VISITOR_QUESTIONS );
1268
1269 if ( faq == null )
1270 {
1271 return getVisitorQuestionList( request );
1272 }
1273
1274 HashMap<String, Object> model = new HashMap<String, Object>( );
1275 setPageTitleProperty( MESSAGE_PAGE_TITLE_MODIFY_VISITOR_QUESTION );
1276
1277 int nIdVisitorQuestion = Integer.parseInt( request.getParameter( PARAMETER_QUESTION_ID ) );
1278 VisitorQuestion visitorQuestion = VisitorQuestionHome.findByPrimaryKey( nIdVisitorQuestion, getPlugin( ) );
1279
1280 String strIdTheme = request.getParameter( PARAMETER_THEME_ID );
1281
1282 model.put( MARK_VISITOR_QUESTION, visitorQuestion );
1283 model.put( MARK_FAQ_ID, faq.getId( ) );
1284 model.put( MARK_WEBAPP_URL, AppPathService.getBaseUrl( request ) );
1285 model.put( MARK_LOCALE, AdminUserService.getLocale( request ).getLanguage( ) );
1286 model.put( MARK_ANSWER, visitorQuestion.getAnswer( ) );
1287 model.put( MARK_THEME_ID, strIdTheme );
1288
1289 HtmlTemplate template;
1290
1291 if ( visitorQuestion.getAnswer( ).equals( "" ) )
1292 {
1293 template = AppTemplateService.getTemplate( TEMPLATE_MODIFY_VISITOR_QUESTION, getLocale( ), model );
1294 }
1295 else
1296 {
1297
1298 AdminUser helpdeskUser = AdminUserHome.findByPrimaryKey( visitorQuestion.getIdUser( ) );
1299 List<QuestionAnswer> listQuestionAnswer = QuestionAnswerHome.findByKeywords( visitorQuestion.getAnswer( ),
1300 getPlugin( ) );
1301 model.put( MARK_HELPDESK_USER, helpdeskUser );
1302 model.put( MARK_QUESTION_ANSWER_LIST, listQuestionAnswer );
1303 template = AppTemplateService.getTemplate( TEMPLATE_VIEW_VISITOR_QUESTION, getLocale( ), model );
1304 }
1305
1306 return getAdminPage( template.getHtml( ) );
1307 }
1308
1309
1310
1311
1312
1313
1314 public String getAnswerSelection( HttpServletRequest request )
1315 {
1316 Faq faq = getAuthorizedFaq( request, FaqResourceIdService.PERMISSION_MANAGE_VISITOR_QUESTIONS );
1317
1318 if ( faq == null )
1319 {
1320 return getManageHelpdesk( request );
1321 }
1322
1323 Map<String, Object> model = new HashMap<String, Object>( );
1324 List<Subject> listSubject = (List<Subject>) SubjectHome.getInstance( ).findAll( getPlugin( ) );
1325 model.put( MARK_SUBJECT_LIST, listSubject );
1326 model.put( MARK_PLUGIN, getPlugin( ) );
1327 model.put( MARK_FAQ_ID, faq.getId( ) );
1328 model.put( MARK_QUESTION_LIST, QuestionAnswerHome.findAll( getPlugin( ) ) );
1329
1330 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_ANSWER_SELECTION, getLocale( ), model );
1331
1332 return template.getHtml( );
1333 }
1334
1335
1336
1337
1338
1339
1340 public String getVisitorQuestionList( HttpServletRequest request )
1341 {
1342 Faq faq = getAuthorizedFaq( request, FaqResourceIdService.PERMISSION_MANAGE_VISITOR_QUESTIONS );
1343
1344 if ( faq == null )
1345 {
1346 return getManageHelpdesk( request );
1347 }
1348
1349 String strIdTheme = request.getParameter( PARAMETER_THEME_ID );
1350 Theme theme = null;
1351
1352 if ( ( strIdTheme != null ) && strIdTheme.matches( REGEX_ID ) )
1353 {
1354 int nIdTheme = Integer.parseInt( strIdTheme );
1355 theme = (Theme) ThemeHome.getInstance( ).findByPrimaryKey( nIdTheme, getPlugin( ) );
1356 }
1357
1358 Collection<Theme> listThemes = (Collection<Theme>) ThemeHome.getInstance( )
1359 .findByIdFaq( faq.getId( ), getPlugin( ) );
1360
1361 if ( ( theme == null ) && ( listThemes.size( ) > 0 ) )
1362 {
1363 theme = listThemes.iterator( ).next( );
1364 }
1365
1366 Map<String, Object> model = new HashMap<String, Object>( );
1367 setPageTitleProperty( MESSAGE_PAGE_TITLE_VISITOR_QUESTION_LIST );
1368
1369 model.put( MARK_THEME_LIST, listThemes );
1370 model.put( MARK_THEME, theme );
1371 model.put( MARK_FAQ, faq );
1372 model.put( MARK_PLUGIN, getPlugin( ) );
1373
1374 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_VISITOR_QUESTION_LIST, getLocale( ), model );
1375
1376 return getAdminPage( template.getHtml( ) );
1377 }
1378
1379
1380
1381
1382
1383
1384 public String doModifyVisitorQuestion( HttpServletRequest request )
1385 {
1386 Faq faq = getAuthorizedFaq( request, FaqResourceIdService.PERMISSION_MANAGE_VISITOR_QUESTIONS );
1387
1388 if ( faq == null )
1389 {
1390 return AdminMessageService.getMessageUrl( request, MESSAGE_ACCESS_DENIED, AdminMessage.TYPE_STOP );
1391 }
1392
1393 String strIdVisitorQuestion = request.getParameter( PARAMETER_QUESTION_ID );
1394 int nIdVisitorQuestion = Integer.parseInt( strIdVisitorQuestion );
1395 String strLastname = request.getParameter( PARAMETER_LAST_NAME );
1396 String strFirstname = request.getParameter( PARAMETER_FIRST_NAME );
1397 String strEmail = request.getParameter( PARAMETER_EMAIL );
1398 String strQuestion = request.getParameter( PARAMETER_QUESTION );
1399 String strAnswer = request.getParameter( PARAMETER_ANSWER );
1400 String strSubject = request.getParameter( PARAMETER_MAIL_SUBJECT );
1401 String strIdTheme = request.getParameter( PARAMETER_THEME_ID );
1402 AdminUser user = getUser( );
1403
1404 VisitorQuestions/VisitorQuestion.html#VisitorQuestion">VisitorQuestion visitorQuestion = new VisitorQuestion( );
1405 visitorQuestion.setIdVisitorQuestion( nIdVisitorQuestion );
1406 visitorQuestion.setLastname( strLastname );
1407 visitorQuestion.setFirstname( strFirstname );
1408 visitorQuestion.setEmail( strEmail );
1409 visitorQuestion.setQuestion( strQuestion );
1410 visitorQuestion.setAnswer( strAnswer );
1411 visitorQuestion.setIdUser( user.getUserId( ) );
1412
1413
1414 if ( request.getParameter( PARAMETER_ANSWER ).equals( "" ) )
1415 {
1416 return AdminMessageService.getMessageUrl( request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP );
1417 }
1418
1419 VisitorQuestionHome.update( visitorQuestion, getPlugin( ) );
1420
1421 String strPortalUrl = AppPathService.getBaseUrl( request );
1422
1423 HashMap<String, Object> model = new HashMap<String, Object>( );
1424
1425 model.put( MARK_QUESTION, visitorQuestion.getQuestion( ) );
1426 model.put( MARK_ANSWER, visitorQuestion.getAnswer( ) );
1427 model.put( MARK_PORTAL_URL, strPortalUrl );
1428 model.put( MARK_FAQ_ID, faq.getId( ) );
1429
1430 String strPortal = AppPropertiesService.getProperty( MESSAGE_PORTAL_NAME );
1431 String strEmailWebmaster = AppPropertiesService.getProperty( MESSAGE_MAIL_HELPDESK_SENDER );
1432
1433 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_SEND_ANSWER, request.getLocale( ), model );
1434
1435 String strMessageText = template.getHtml( );
1436
1437 strSubject = AppPropertiesService.getProperty( PROPERTY_MAIL_SUBJECT_PREFIX )
1438 + CONSTANT_SPACE + strPortal + CONSTANT_MINUS + strSubject;
1439
1440 MailService.sendMailHtml( visitorQuestion.getEmail( ), strPortal, strEmailWebmaster, strSubject, strMessageText );
1441
1442 if ( request.getParameter( PARAMETER_ADD_QUESTION_ANSWER ) == null )
1443 {
1444
1445 UrlItem url = new UrlItem( JSP_VISITOR_QUESTION_LIST );
1446 url.addParameter( PARAMETER_FAQ_ID, faq.getId( ) );
1447
1448 return url.getUrl( );
1449 }
1450 else
1451 {
1452 UrlItem url = new UrlItem( JSP_CREATE_QUESTION_ANSWER );
1453 url.addParameter( PARAMETER_FAQ_ID, faq.getId( ) );
1454 url.addParameter( PARAMETER_QUESTION_ID, nIdVisitorQuestion );
1455 url.addParameter( PARAMETER_THEME_ID, strIdTheme );
1456 return url.getUrl( );
1457 }
1458 }
1459
1460
1461
1462
1463
1464
1465 public String getArchivedQuestionList( HttpServletRequest request )
1466 {
1467 Faq faq = getAuthorizedFaq( request, FaqResourceIdService.PERMISSION_MANAGE_VISITOR_QUESTIONS );
1468
1469 if ( faq == null )
1470 {
1471 return getVisitorQuestionList( request );
1472 }
1473
1474 Collection<Theme> listThemes = (Collection<Theme>) ThemeHome.getInstance( )
1475 .findByIdFaq( faq.getId( ), getPlugin( ) );
1476
1477 String strIdTheme = request.getParameter( PARAMETER_THEME_ID );
1478 Theme theme = null;
1479
1480 if ( ( strIdTheme != null ) && strIdTheme.matches( REGEX_ID ) )
1481 {
1482 int nIdTheme = Integer.parseInt( strIdTheme );
1483 theme = (Theme) ThemeHome.getInstance( ).findByPrimaryKey( nIdTheme, getPlugin( ) );
1484 }
1485
1486 if ( ( theme == null ) && ( listThemes.size( ) > 0 ) )
1487 {
1488 theme = listThemes.iterator( ).next( );
1489 }
1490
1491 Collection<VisitorQuestion> listArchivedQuestions = null;
1492
1493 if ( theme != null )
1494 {
1495 listArchivedQuestions = VisitorQuestionHome.findArchivedQuestionsByTheme( theme.getId( ), getPlugin( ) );
1496 }
1497
1498 HashMap model = new HashMap( );
1499 setPageTitleProperty( MESSAGE_PAGE_TITLE_ARCHIVED_QUESTION_LIST );
1500
1501 model.put( MARK_THEME_LIST, listThemes );
1502 model.put( MARK_ARCHIVED_QUESTION_LIST, listArchivedQuestions );
1503 model.put( MARK_THEME, theme );
1504 model.put( MARK_FAQ, faq );
1505 model.put( MARK_PLUGIN, getPlugin( ) );
1506
1507 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_ARCHIVED_QUESTION_LIST, getLocale( ), model );
1508
1509 return getAdminPage( template.getHtml( ) );
1510 }
1511
1512
1513
1514
1515
1516
1517 public String doRemoveVisitorQuestion( HttpServletRequest request )
1518 {
1519 Faq faq = getAuthorizedFaq( request, FaqResourceIdService.PERMISSION_MANAGE_VISITOR_QUESTIONS );
1520
1521 if ( faq == null )
1522 {
1523 return AdminMessageService.getMessageUrl( request, MESSAGE_ACCESS_DENIED, AdminMessage.TYPE_STOP );
1524 }
1525
1526 int nIdQuestionAnswer = Integer.parseInt( request.getParameter( PARAMETER_QUESTION_ID ) );
1527 VisitorQuestionHome.remove( nIdQuestionAnswer, getPlugin( ) );
1528
1529
1530 UrlItem url = new UrlItem( JSP_ARCHIVED_QUESTION_LIST );
1531 url.addParameter( PARAMETER_THEME_ID, request.getParameter( PARAMETER_THEME_ID ) );
1532 url.addParameter( PARAMETER_FAQ_ID, faq.getId( ) );
1533
1534 return url.getUrl( );
1535 }
1536
1537
1538
1539
1540
1541
1542 public String getImportQuestionAnswerList( HttpServletRequest request )
1543 {
1544 Faq faq = getAuthorizedFaq( request, FaqResourceIdService.PERMISSION_IMPORT_QUESTIONS_ANSWERS );
1545
1546 if ( faq == null )
1547 {
1548 return getManageHelpdesk( request );
1549 }
1550
1551 Map<String, Object> model = new HashMap<String, Object>( );
1552 setPageTitleProperty( MESSAGE_PAGE_TITLE_IMPORT_QUESTION_ANSWER_LIST );
1553
1554 model.put( MARK_FAQ, faq );
1555
1556 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_IMPORT_QUESTION_ANSWER_LIST, getLocale( ),
1557 model );
1558
1559 return getAdminPage( template.getHtml( ) );
1560 }
1561
1562
1563
1564
1565
1566
1567
1568 private String insertQuestionAnswers( HttpServletRequest request, List<String[]> listQuestionAnswers, Faq faq
1569 , boolean bDeleteList, Collection<QuestionAnswer> questionAnswerList)
1570 {
1571 int nRowNumber = 0;
1572
1573 boolean bAvoidFirstColumn = Boolean.parseBoolean( AppPropertiesService.getProperty( PROPERTY_CSV_HEADER,
1574 DEFAULT_CSV_HEADER ) );
1575 String strCsvColumnsList = AppPropertiesService.getProperty( PROPERTY_CSV_COLUMNS_LIST, DEFAULT_CSV_COLUMNS );
1576 String[] arrayCsvColumnsList = strCsvColumnsList.split( DEFAULT_CONSTANT_DELIMITER_COLUMNS_LIST );
1577
1578 if( !bDeleteList )
1579 {
1580
1581 Collections.reverse( listQuestionAnswers );
1582 }
1583
1584 for ( String[] strRow : listQuestionAnswers )
1585 {
1586 if ( !( ( nRowNumber == 0 ) && bAvoidFirstColumn ) )
1587 {
1588 int nColumnId = 0;
1589 QuestionAnsweress/QuestionAnswer.html#QuestionAnswer">QuestionAnswer questionAnswer = new QuestionAnswer( );
1590
1591 if ( strRow.length != arrayCsvColumnsList.length )
1592 {
1593 return AdminMessageService.getMessageUrl( request, MESSAGE_CSV_COLUMNS_LIST_ERROR,
1594 new String[] { String.valueOf( nRowNumber + 1 ), strCsvColumnsList },
1595 AdminMessage.TYPE_ERROR );
1596 }
1597
1598
1599 for ( String strField : strRow )
1600 {
1601 EnumColumns eColumn = EnumColumns.getByName( arrayCsvColumnsList[nColumnId] );
1602
1603 if ( eColumn != null )
1604 {
1605 switch ( eColumn )
1606 {
1607 case SUBJECT_ID:
1608
1609 int nIdSubject = validateSubjectId( strField, faq );
1610
1611 if ( nIdSubject < 0 )
1612 {
1613 return getAdminMessageError( request, nColumnId,
1614 arrayCsvColumnsList[nColumnId], nRowNumber );
1615 }
1616
1617 questionAnswer.setIdSubject( nIdSubject );
1618
1619 break;
1620
1621 case ORDER_ID:
1622
1623 if( bDeleteList)
1624 {
1625 int nIdOrder = validateIdOrder( strField, faq );
1626
1627 if ( nIdOrder < 0 )
1628 {
1629 return getAdminMessageError( request, nColumnId,
1630 arrayCsvColumnsList[nColumnId], nRowNumber );
1631 }
1632
1633 questionAnswer.setIdOrder( nIdOrder );
1634
1635 }
1636 break;
1637
1638 case QUESTION:
1639
1640 String strQuestion = validateQuestion( strField );
1641
1642 if ( strQuestion == null )
1643 {
1644 return getAdminMessageError( request, nColumnId,
1645 arrayCsvColumnsList[nColumnId], nRowNumber );
1646 }
1647
1648 questionAnswer.setQuestion( strQuestion );
1649
1650 break;
1651
1652 case ANSWER:
1653
1654 String strAnswer = validateAnswer( strField );
1655
1656 if ( strAnswer == null )
1657 {
1658 return getAdminMessageError( request, nColumnId,
1659 arrayCsvColumnsList[nColumnId], nRowNumber );
1660 }
1661
1662 questionAnswer.setAnswer( strAnswer );
1663
1664 break;
1665
1666 default:
1667 break;
1668 }
1669 }
1670
1671 nColumnId++;
1672 }
1673
1674 questionAnswer.setCreationDate( new Date( ) );
1675 questionAnswer.setStatus( 1 );
1676
1677
1678 questionAnswerList.add( questionAnswer );
1679 }
1680
1681 nRowNumber++;
1682 }
1683
1684
1685 if ( bDeleteList )
1686 {
1687 QuestionAnswerHome.removeAll( getPlugin( ) );
1688 }
1689
1690
1691 for ( QuestionAnswer questionAnswer : questionAnswerList )
1692 {
1693 QuestionAnswerHome.create( questionAnswer, getPlugin( ) );
1694 }
1695
1696 return null;
1697 }
1698
1699
1700
1701
1702
1703
1704
1705 public String doConfirmImportQuestionAnswerList( HttpServletRequest request )
1706 {
1707 Faq faq = getAuthorizedFaq( request, FaqResourceIdService.PERMISSION_IMPORT_QUESTIONS_ANSWERS );
1708
1709 if ( faq == null )
1710 {
1711 return AdminMessageService.getMessageUrl( request, MESSAGE_ACCESS_DENIED, AdminMessage.TYPE_STOP );
1712 }
1713
1714 Collection<QuestionAnswer> questionAnswerList = new ArrayList<QuestionAnswer>( );
1715
1716 List<String[]> listQuestionAnswers = getRowsFromCsvFile( request, false );
1717
1718 if ( listQuestionAnswers == null )
1719 {
1720 return AdminMessageService.getMessageUrl( request, MESSAGE_CSV_FILE_NOT_VALID, AdminMessage.TYPE_STOP );
1721 }
1722
1723
1724 if ( ( listQuestionAnswers == null ) || ( listQuestionAnswers.size( ) == 0 ) )
1725 {
1726 return AdminMessageService.getMessageUrl( request, MESSAGE_CSV_FILE_EMPTY, AdminMessage.TYPE_STOP );
1727 }
1728
1729 String strInsertResult = insertQuestionAnswers(request, listQuestionAnswers, faq, false, questionAnswerList);
1730 if ( strInsertResult != null )
1731 {
1732 return strInsertResult;
1733 }
1734
1735 UrlItem url = new UrlItem( JSP_LIST_QUESTIONS_ANSWER );
1736 url.addParameter( PARAMETER_FAQ_ID, faq.getId( ) );
1737
1738 return AdminMessageService.getMessageUrl( request, MESSAGE_IMPORT_CSV_OK,
1739 new String[] { String.valueOf( questionAnswerList.size( ) ) }, url.getUrl( ), AdminMessage.TYPE_INFO );
1740 }
1741
1742
1743
1744
1745
1746
1747
1748 public String doImportQuestionAnswerList( HttpServletRequest request )
1749 {
1750 Faq faq = getAuthorizedFaq( request, FaqResourceIdService.PERMISSION_IMPORT_QUESTIONS_ANSWERS );
1751
1752 if ( faq == null )
1753 {
1754 return AdminMessageService.getMessageUrl( request, MESSAGE_ACCESS_DENIED, AdminMessage.TYPE_STOP );
1755 }
1756
1757
1758 Collection<QuestionAnswer> questionAnswerList = new ArrayList<QuestionAnswer>( );
1759 boolean bDeleteList = ( request.getParameter( PARAMETER_DELETE_LIST ) != null ) ? true : false;
1760 List<String[]> listQuestionAnswers = getRowsFromCsvFile( request, true );
1761
1762 if ( listQuestionAnswers == null )
1763 {
1764 return AdminMessageService.getMessageUrl( request, MESSAGE_CSV_FILE_NOT_VALID, AdminMessage.TYPE_STOP );
1765 }
1766
1767
1768 if ( ( listQuestionAnswers == null ) || ( listQuestionAnswers.size( ) == 0 ) )
1769 {
1770 return AdminMessageService.getMessageUrl( request, MESSAGE_CSV_FILE_EMPTY, AdminMessage.TYPE_STOP );
1771 }
1772 else if ( bDeleteList )
1773 {
1774 String strInsertResult = insertQuestionAnswers(request, listQuestionAnswers, faq, bDeleteList, questionAnswerList);
1775 if ( strInsertResult != null )
1776 {
1777 return strInsertResult;
1778 }
1779 }
1780 else
1781 {
1782 MultipartHttpServletRequest multi = (MultipartHttpServletRequest) request;
1783
1784 _csvItem = multi.getFile( PARAMETER_CSV_FILE );
1785
1786 UrlItem url = new UrlItem( JSP_DO_IMPORT_CSV );
1787 url.addParameter( PARAMETER_FAQ_ID, faq.getId( ) );
1788
1789 return AdminMessageService.getMessageUrl( request, MESSAGE_CONFIRM_IMPORT_WITHOUT_DELETING
1790 , url.getUrl( ), AdminMessage.TYPE_CONFIRMATION );
1791 }
1792
1793 UrlItem url = new UrlItem( JSP_LIST_QUESTIONS_ANSWER );
1794 url.addParameter( PARAMETER_FAQ_ID, faq.getId( ) );
1795
1796 return AdminMessageService.getMessageUrl( request, MESSAGE_IMPORT_CSV_OK,
1797 new String[] { String.valueOf( questionAnswerList.size( ) ) }, url.getUrl( ), AdminMessage.TYPE_INFO );
1798 }
1799
1800
1801
1802
1803
1804
1805 public String getManageHelpdeskAdmin( HttpServletRequest request )
1806 {
1807 HashMap model = new HashMap( );
1808 setPageTitleProperty( MESSAGE_PAGE_TITLE_THEMES );
1809
1810 Faq faq = getAuthorizedFaq( request, FaqResourceIdService.PERMISSION_MANAGE_THEMES );
1811
1812 if ( faq == null )
1813 {
1814 return getManageHelpdesk( request );
1815 }
1816
1817 Collection<Theme> listTheme = (Collection<Theme>) ThemeHome.getInstance( )
1818 .findByIdFaq( faq.getId( ), getPlugin( ) );
1819 _nDefaultItemsPerPage = AppPropertiesService.getPropertyInt( PROPERTY_STYLES_PER_PAGE, 10 );
1820 _strCurrentPageIndex = Paginator.getPageIndex( request, Paginator.PARAMETER_PAGE_INDEX, _strCurrentPageIndex );
1821 _nItemsPerPage = Paginator.getItemsPerPage( request, Paginator.PARAMETER_ITEMS_PER_PAGE, _nItemsPerPage,
1822 _nDefaultItemsPerPage );
1823
1824 UrlItem url = new UrlItem( JSP_MANAGE_HELPDESK_ADMIN );
1825 url.addParameter( PARAMETER_FAQ_ID, faq.getId( ) );
1826
1827 Paginator paginator = new Paginator( (List<Theme>) listTheme, _nItemsPerPage, url.getUrl( ),
1828 Paginator.PARAMETER_PAGE_INDEX, _strCurrentPageIndex );
1829
1830 model.put( MARK_NB_ITEMS_PER_PAGE, String.valueOf( _nItemsPerPage ) );
1831 model.put( MARK_PAGINATOR, paginator );
1832 model.put( MARK_THEME_LIST, paginator.getPageItems( ) );
1833 model.put( MARK_PLUGIN, getPlugin( ) );
1834 model.put( MARK_FAQ, faq );
1835
1836 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_THEME_LIST, getLocale( ), model );
1837
1838 return getAdminPage( template.getHtml( ) );
1839 }
1840
1841
1842
1843
1844
1845
1846 public String getConfirmRemoveTheme( HttpServletRequest request )
1847 {
1848 Faq faq = getAuthorizedFaq( request, FaqResourceIdService.PERMISSION_MANAGE_THEMES );
1849
1850 if ( faq == null )
1851 {
1852 return AdminMessageService.getMessageUrl( request, MESSAGE_ACCESS_DENIED, AdminMessage.TYPE_STOP );
1853 }
1854
1855 int nIdTheme = Integer.parseInt( request.getParameter( PARAMETER_THEME_ID ) );
1856 Theme="../../../../../../fr/paris/lutece/plugins/helpdesk/business/Theme.html#Theme">Theme theme = (Theme) ThemeHome.getInstance( ).findByPrimaryKey( nIdTheme, getPlugin( ) );
1857 Collection<VisitorQuestion> listQuestion = ThemeHome.findQuestion( nIdTheme, getPlugin( ) );
1858 UrlItem url = new UrlItem( JSP_DO_REMOVE_THEME );
1859 url.addParameter( PARAMETER_THEME_ID, nIdTheme );
1860 url.addParameter( PARAMETER_FAQ_ID, faq.getId( ) );
1861
1862 if ( theme == null )
1863 {
1864 return JSP_MANAGE_HELPDESK_LIST;
1865 }
1866
1867 if ( ( listQuestion.size( ) != 0 ) )
1868 {
1869 return AdminMessageService.getMessageUrl( request, MESSAGE_CANNOT_DELETE_THEME_QUESTION_EXISTS,
1870 url.getUrl( ), AdminMessage.TYPE_STOP );
1871 }
1872
1873 if ( theme.getChilds( getPlugin( ) ).size( ) > 0 )
1874 {
1875 return AdminMessageService.getMessageUrl( request, MESSAGE_CANNOT_DELETE_THEME_SUB_THEME_EXISTS,
1876 AdminMessage.TYPE_STOP );
1877 }
1878
1879 return AdminMessageService.getMessageUrl( request, MESSAGE_CONFIRM_DELETE_THEME, url.getUrl( ),
1880 AdminMessage.TYPE_CONFIRMATION );
1881 }
1882
1883
1884
1885
1886
1887
1888 public String doRemoveTheme( HttpServletRequest request )
1889 {
1890 Faq faq = getAuthorizedFaq( request, FaqResourceIdService.PERMISSION_MANAGE_THEMES );
1891
1892 if ( faq == null )
1893 {
1894 return AdminMessageService.getMessageUrl( request, MESSAGE_ACCESS_DENIED, AdminMessage.TYPE_STOP );
1895 }
1896
1897 UrlItem url = new UrlItem( JSP_MANAGE_HELPDESK_LIST );
1898 url.addParameter( PARAMETER_FAQ_ID, faq.getId( ) );
1899
1900 int nIdTheme = Integer.parseInt( request.getParameter( PARAMETER_THEME_ID ) );
1901 Theme="../../../../../../fr/paris/lutece/plugins/helpdesk/business/Theme.html#Theme">Theme theme = (Theme) ThemeHome.getInstance( ).findByPrimaryKey( nIdTheme, getPlugin( ) );
1902 Collection<VisitorQuestion> listQuestion = ThemeHome.findQuestion( nIdTheme, getPlugin( ) );
1903
1904 if ( theme == null )
1905 {
1906 return url.getUrl( );
1907 }
1908
1909 if ( ( listQuestion.size( ) == 0 ) && ( theme.getChilds( getPlugin( ) ).size( ) == 0 ) )
1910 {
1911 if ( theme.getIdParent( ) == 0 )
1912 {
1913 ThemeHome.getInstance( ).removeLinkToFaq( theme.getId( ), faq.getId( ), getPlugin( ) );
1914 }
1915
1916 Collection<VisitorQuestion> visitorQuestionList = VisitorQuestionHome.findArchivedQuestionsByTheme( theme.getId( ),
1917 getPlugin( ) );
1918
1919 for ( VisitorQuestion visitorQuestion : visitorQuestionList )
1920 {
1921 VisitorQuestionHome.remove( visitorQuestion.getIdVisitorQuestion( ), getPlugin( ) );
1922 }
1923
1924 ThemeHome.getInstance( ).remove( nIdTheme, faq.getId( ), getPlugin( ) );
1925 }
1926
1927
1928 return url.getUrl( );
1929 }
1930
1931
1932
1933
1934
1935
1936 public String getCreateTheme( HttpServletRequest request )
1937 {
1938 Faq faq = getAuthorizedFaq( request, FaqResourceIdService.PERMISSION_MANAGE_THEMES );
1939
1940 if ( faq == null )
1941 {
1942 return getManageHelpdeskAdmin( request );
1943 }
1944
1945 Map<String, Object> model = new HashMap<String, Object>( );
1946
1947 setPageTitleProperty( MESSAGE_PAGE_TITLE_CREATE_THEME );
1948
1949 Collection<Theme> listThemes = (Collection<Theme>) ThemeHome.getInstance( )
1950 .findByIdFaq( faq.getId( ), getPlugin( ) );
1951 Theme rootTheme = ThemeHome.getVirtualRootTheme( getLocale( ) );
1952 model.put( MARK_THEME_LIST, listThemes );
1953 model.put( MARK_PLUGIN, getPlugin( ) );
1954 model.put( MARK_DEFAULT_VALUE, rootTheme.getId( ) );
1955 model.put( MARK_FAQ_ID, request.getParameter( PARAMETER_FAQ_ID ) );
1956
1957 ReferenceList listMailingLists = AdminMailingListService.getMailingLists( getUser( ) );
1958 model.put( MARK_MAILINGLISTS_LIST, listMailingLists );
1959
1960 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_CREATE_THEME, getLocale( ), model );
1961
1962 return getAdminPage( template.getHtml( ) );
1963 }
1964
1965
1966
1967
1968
1969
1970 public String getModifyTheme( HttpServletRequest request )
1971 {
1972 Faq faq = getAuthorizedFaq( request, FaqResourceIdService.PERMISSION_MANAGE_THEMES );
1973
1974 if ( faq == null )
1975 {
1976 return getManageHelpdeskAdmin( request );
1977 }
1978
1979 HashMap model = new HashMap( );
1980
1981 setPageTitleProperty( MESSAGE_PAGE_TITLE_MODIFY_THEME );
1982
1983 String strIdTheme = request.getParameter( PARAMETER_THEME_ID );
1984
1985 int nIdTheme = Integer.parseInt( strIdTheme );
1986 Theme="../../../../../../fr/paris/lutece/plugins/helpdesk/business/Theme.html#Theme">Theme theme = (Theme) ThemeHome.getInstance( ).findByPrimaryKey( nIdTheme, getPlugin( ) );
1987
1988 if ( theme == null )
1989 {
1990 return getManageHelpdeskAdmin( request );
1991 }
1992
1993 model.put( MARK_THEME, theme );
1994 model.put( MARK_PLUGIN, getPlugin( ) );
1995 model.put( MARK_FAQ_ID, faq.getId( ) );
1996
1997 Collection<Theme> listTheme = (Collection<Theme>) ThemeHome.getInstance( )
1998 .findByIdFaq( faq.getId( ), getPlugin( ) );
1999 model.put( MARK_THEME_LIST, listTheme );
2000
2001 ReferenceList listMailingLists = AdminMailingListService.getMailingLists( getUser( ) );
2002 model.put( MARK_MAILINGLISTS_LIST, listMailingLists );
2003
2004 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MODIFY_THEME, getLocale( ), model );
2005
2006 return getAdminPage( template.getHtml( ) );
2007 }
2008
2009
2010
2011
2012
2013
2014 public String doCreateTheme( HttpServletRequest request )
2015 {
2016 Faq faq = getAuthorizedFaq( request, FaqResourceIdService.PERMISSION_MANAGE_THEMES );
2017
2018 if ( faq == null )
2019 {
2020 return AdminMessageService.getMessageUrl( request, MESSAGE_ACCESS_DENIED, AdminMessage.TYPE_STOP );
2021 }
2022
2023 String strTheme = request.getParameter( PARAMETER_THEME );
2024 String strIdQuestionMailingList = request.getParameter( PARAMETER_QUESTION_MAILINGLIST );
2025 String strIdParent = request.getParameter( PARAMETER_PARENT_ID );
2026
2027
2028 if ( ( strTheme == null ) || ( strIdParent == null ) || strTheme.trim( ).equals( "" ) ||
2029 strIdParent.equals( "" ) || ( faq == null ) )
2030 {
2031 return AdminMessageService.getMessageUrl( request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP );
2032 }
2033
2034
2035 if ( ( strIdQuestionMailingList == null ) || strIdQuestionMailingList.trim( ).equals( "" ) )
2036 {
2037 return AdminMessageService.getMessageUrl( request, MESSAGE_NO_MAILING_LIST_EXIST_THEME,
2038 AdminMessage.TYPE_STOP );
2039 }
2040
2041 int nIdQuestionMailingList = Integer.parseInt( strIdQuestionMailingList );
2042 int nIdParent = Integer.parseInt( strIdParent );
2043
2044 Themeins/helpdesk/business/Theme.html#Theme">Theme theme = new Theme( );
2045 theme.setText( strTheme );
2046 theme.setIdMailingList( nIdQuestionMailingList );
2047 theme.setIdParent( nIdParent );
2048 theme = (Theme) ThemeHome.getInstance( ).create( theme, faq.getId( ), getPlugin( ) );
2049
2050 if ( theme.getIdParent( ) == 0 )
2051 {
2052 ThemeHome.getInstance( ).createLinkToFaq( theme.getId( ), faq.getId( ), getPlugin( ) );
2053 }
2054
2055
2056 UrlItem url = new UrlItem( JSP_MANAGE_HELPDESK_LIST );
2057 url.addParameter( PARAMETER_FAQ_ID, faq.getId( ) );
2058
2059 return url.getUrl( );
2060 }
2061
2062
2063
2064
2065
2066
2067 public String doModifyTheme( HttpServletRequest request )
2068 {
2069 Faq faq = getAuthorizedFaq( request, FaqResourceIdService.PERMISSION_MANAGE_THEMES );
2070
2071 if ( faq == null )
2072 {
2073 return AdminMessageService.getMessageUrl( request, MESSAGE_ACCESS_DENIED, AdminMessage.TYPE_STOP );
2074 }
2075
2076 String strTheme = request.getParameter( PARAMETER_THEME );
2077 String strIdTheme = request.getParameter( PARAMETER_THEME_ID );
2078 String strIdQuestionMailingList = request.getParameter( PARAMETER_QUESTION_MAILINGLIST );
2079 String strIdParent = request.getParameter( PARAMETER_PARENT_ID );
2080
2081
2082 if ( ( strTheme == null ) || ( strIdTheme == null ) || ( strIdParent == null ) || strIdTheme.equals( "" ) ||
2083 strTheme.equals( "" ) || strIdParent.equals( "" ) )
2084 {
2085 return AdminMessageService.getMessageUrl( request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP );
2086 }
2087
2088 int nIdTheme = Integer.parseInt( strIdTheme );
2089 int nIdParent = Integer.parseInt( strIdParent );
2090
2091
2092 if ( ( strIdQuestionMailingList == null ) || strIdQuestionMailingList.trim( ).equals( "" ) )
2093 {
2094 return AdminMessageService.getMessageUrl( request, MESSAGE_NO_MAILING_LIST_EXIST_THEME,
2095 AdminMessage.TYPE_STOP );
2096 }
2097
2098 int nIdQuestionMailingList = Integer.parseInt( strIdQuestionMailingList );
2099
2100 Themeins/helpdesk/business/Theme.html#Theme">Theme theme = new Theme( );
2101 theme.setId( nIdTheme );
2102 theme.setText( strTheme );
2103
2104 if ( theme.getIdParent( ) == 0 )
2105 {
2106 ThemeHome.getInstance( ).removeLinkToFaq( nIdTheme, faq.getId( ), getPlugin( ) );
2107 }
2108
2109 if ( nIdParent == 0 )
2110 {
2111 ThemeHome.getInstance( ).createLinkToFaq( nIdTheme, faq.getId( ), getPlugin( ) );
2112 }
2113
2114 theme.setIdParent( nIdParent );
2115 theme.setIdMailingList( nIdQuestionMailingList );
2116
2117 ThemeHome.getInstance( ).update( theme, faq.getId( ), getPlugin( ) );
2118
2119
2120 UrlItem url = new UrlItem( JSP_MANAGE_HELPDESK_LIST );
2121 url.addParameter( PARAMETER_FAQ_ID, faq.getId( ) );
2122
2123 return url.getUrl( );
2124 }
2125
2126
2127
2128
2129
2130
2131 public String doGoDownTheme( HttpServletRequest request )
2132 {
2133 Faq faq = getAuthorizedFaq( request, FaqResourceIdService.PERMISSION_MANAGE_THEMES );
2134
2135 if ( faq == null )
2136 {
2137 return AdminMessageService.getMessageUrl( request, MESSAGE_ACCESS_DENIED, AdminMessage.TYPE_STOP );
2138 }
2139
2140 String strIdTheme = request.getParameter( PARAMETER_THEME_ID );
2141 int nIdTheme = Integer.parseInt( strIdTheme );
2142 ThemeHome.getInstance( ).goDown( nIdTheme, faq.getId( ), getPlugin( ) );
2143
2144 UrlItem url = new UrlItem( JSP_MANAGE_HELPDESK_LIST );
2145 url.addParameter( PARAMETER_FAQ_ID, faq.getId( ) );
2146
2147 return url.getUrl( );
2148 }
2149
2150
2151
2152
2153
2154
2155 public String doGoUpTheme( HttpServletRequest request )
2156 {
2157 Faq faq = getAuthorizedFaq( request, FaqResourceIdService.PERMISSION_MANAGE_THEMES );
2158
2159 if ( faq == null )
2160 {
2161 return AdminMessageService.getMessageUrl( request, MESSAGE_ACCESS_DENIED, AdminMessage.TYPE_STOP );
2162 }
2163
2164 String strIdTheme = request.getParameter( PARAMETER_THEME_ID );
2165 int nIdTheme = Integer.parseInt( strIdTheme );
2166 ThemeHome.getInstance( ).goUp( nIdTheme, faq.getId( ), getPlugin( ) );
2167
2168 UrlItem url = new UrlItem( JSP_MANAGE_HELPDESK_LIST );
2169 url.addParameter( PARAMETER_FAQ_ID, faq.getId( ) );
2170
2171 return url.getUrl( );
2172 }
2173
2174
2175
2176
2177
2178
2179 public String doGoInTheme( HttpServletRequest request )
2180 {
2181 Faq faq = getAuthorizedFaq( request, FaqResourceIdService.PERMISSION_MANAGE_THEMES );
2182
2183 if ( faq == null )
2184 {
2185 return AdminMessageService.getMessageUrl( request, MESSAGE_ACCESS_DENIED, AdminMessage.TYPE_STOP );
2186 }
2187
2188 UrlItem url = new UrlItem( JSP_MANAGE_HELPDESK_LIST );
2189 url.addParameter( PARAMETER_FAQ_ID, request.getParameter( PARAMETER_FAQ_ID ) );
2190
2191 String strIdTheme = request.getParameter( PARAMETER_THEME_ID );
2192 int nIdTheme = Integer.parseInt( strIdTheme );
2193 Theme="../../../../../../fr/paris/lutece/plugins/helpdesk/business/Theme.html#Theme">Theme theme = (Theme) ThemeHome.getInstance( ).findByPrimaryKey( nIdTheme, getPlugin( ) );
2194
2195 if ( theme == null )
2196 {
2197 return url.getUrl( );
2198 }
2199
2200 if ( theme.getIdParent( ) == 0 )
2201 {
2202 ThemeHome.getInstance( ).removeLinkToFaq( nIdTheme, faq.getId( ), getPlugin( ) );
2203 }
2204
2205 ThemeHome.getInstance( ).goIn( nIdTheme, faq.getId( ), getPlugin( ) );
2206
2207 return url.getUrl( );
2208 }
2209
2210
2211
2212
2213
2214
2215 public String doGoOutTheme( HttpServletRequest request )
2216 {
2217 Faq faq = getAuthorizedFaq( request, FaqResourceIdService.PERMISSION_MANAGE_THEMES );
2218
2219 if ( faq == null )
2220 {
2221 return AdminMessageService.getMessageUrl( request, MESSAGE_ACCESS_DENIED, AdminMessage.TYPE_STOP );
2222 }
2223
2224 UrlItem url = new UrlItem( JSP_MANAGE_HELPDESK_LIST );
2225 url.addParameter( PARAMETER_FAQ_ID, request.getParameter( PARAMETER_FAQ_ID ) );
2226
2227 String strIdTheme = request.getParameter( PARAMETER_THEME_ID );
2228 int nIdTheme = Integer.parseInt( strIdTheme );
2229 ThemeHome.getInstance( ).goOut( nIdTheme, faq.getId( ), getPlugin( ) );
2230
2231 Theme="../../../../../../fr/paris/lutece/plugins/helpdesk/business/Theme.html#Theme">Theme theme = (Theme) ThemeHome.getInstance( ).findByPrimaryKey( nIdTheme, getPlugin( ) );
2232
2233 if ( theme == null )
2234 {
2235 return url.getUrl( );
2236 }
2237
2238 if ( theme.getIdParent( ) == 0 )
2239 {
2240 ThemeHome.getInstance( ).removeLinkToFaq( nIdTheme, faq.getId( ), getPlugin( ) );
2241 ThemeHome.getInstance( ).createLinkToFaq( nIdTheme, faq.getId( ), getPlugin( ) );
2242 }
2243
2244 return url.getUrl( );
2245 }
2246
2247
2248
2249
2250
2251
2252 public String getManageHelpdesk( HttpServletRequest request )
2253 {
2254 HashMap<String, Object> model = new HashMap<String, Object>( );
2255 Collection<HashMap> subModelFaqList = new ArrayList<HashMap>( );
2256
2257 setPageTitleProperty( MESSAGE_PAGE_TITLE_FAQ_LIST );
2258
2259 Collection<Faq> listFaq = FaqHome.findAll( getPlugin( ) );
2260 listFaq = AdminWorkgroupService.getAuthorizedCollection( listFaq, getUser( ) );
2261
2262 _nDefaultItemsPerPage = AppPropertiesService.getPropertyInt( PROPERTY_STYLES_PER_PAGE, 10 );
2263 _strCurrentPageIndex = Paginator.getPageIndex( request, Paginator.PARAMETER_PAGE_INDEX, _strCurrentPageIndex );
2264 _nItemsPerPage = Paginator.getItemsPerPage( request, Paginator.PARAMETER_ITEMS_PER_PAGE, _nItemsPerPage,
2265 _nDefaultItemsPerPage );
2266
2267 Paginator paginator = new Paginator( (List<Faq>) listFaq, _nItemsPerPage, JSP_HELPDESK_MANAGE,
2268 Paginator.PARAMETER_PAGE_INDEX, _strCurrentPageIndex );
2269
2270 for ( Faq faq : (List<Faq>) paginator.getPageItems( ) )
2271 {
2272 HashMap subModelFaq = new HashMap( );
2273 subModelFaq.put( MARK_FAQ, faq );
2274
2275 for ( String strPermission : getAuthorizedActionCollection( faq ) )
2276 {
2277 subModelFaq.put( strPermission, strPermission );
2278 }
2279
2280 subModelFaqList.add( subModelFaq );
2281 }
2282
2283 model.put( MARK_NB_ITEMS_PER_PAGE, "" + _nItemsPerPage );
2284 model.put( MARK_PAGINATOR, paginator );
2285 model.put( MARK_FAQ_LIST, subModelFaqList );
2286 model.put( MARK_PLUGIN, getPlugin( ) );
2287
2288 if ( RBACService.isAuthorized( Faq.RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID,
2289 FaqResourceIdService.PERMISSION_CREATE, getUser( ) ) )
2290 {
2291 model.put( FaqResourceIdService.PERMISSION_CREATE, FaqResourceIdService.PERMISSION_CREATE );
2292 }
2293
2294 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MANAGE_HELPDESK, getLocale( ), model );
2295
2296 return getAdminPage( template.getHtml( ) );
2297 }
2298
2299
2300
2301
2302
2303
2304 public String getCreateFaq( HttpServletRequest request )
2305 {
2306 if ( !RBACService.isAuthorized( Faq.RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID,
2307 FaqResourceIdService.PERMISSION_CREATE, getUser( ) ) )
2308 {
2309 return getManageHelpdesk( request );
2310 }
2311
2312
2313 HashMap model = new HashMap( );
2314 setPageTitleProperty( MESSAGE_PAGE_TITLE_CREATE_FAQ );
2315
2316 model.put( MARK_PLUGIN, getPlugin( ) );
2317 model.put( MARK_ROLE_KEY_LIST, RoleHome.getRolesList( ) );
2318 model.put( MARK_DEFAULT_VALUE_ROLE_KEY, Faq.ROLE_NONE );
2319 model.put( MARK_DEFAULT_VALUE_WORKGROUP_KEY, AdminWorkgroupService.ALL_GROUPS );
2320 model.put( MARK_WORKGROUP_KEY_LIST, AdminWorkgroupService.getUserWorkgroups( getUser( ), getLocale( ) ) );
2321
2322 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_CREATE_FAQ, getLocale( ), model );
2323
2324 return getAdminPage( template.getHtml( ) );
2325 }
2326
2327
2328
2329
2330
2331
2332 public String doCreateFaq( HttpServletRequest request )
2333 {
2334 if ( !RBACService.isAuthorized( Faq.RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID,
2335 FaqResourceIdService.PERMISSION_CREATE, getUser( ) ) )
2336 {
2337 return AdminMessageService.getMessageUrl( request, MESSAGE_ACCESS_DENIED, AdminMessage.TYPE_STOP );
2338 }
2339
2340 String strName = request.getParameter( PARAMETER_NAME );
2341 String strDescription = request.getParameter( PARAMETER_DESCRIPTION );
2342 String strRoleKey = request.getParameter( PARAMETER_ROLE_KEY );
2343 String strWorkgroupKey = request.getParameter( PARAMETER_WORKGROUP_KEY );
2344
2345
2346 if ( ( strName == null ) || strName.equals( "" ) || ( strDescription == null ) || strDescription.equals( "" ) ||
2347 ( strRoleKey == null ) || ( strWorkgroupKey == null ) )
2348 {
2349 return AdminMessageService.getMessageUrl( request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP );
2350 }
2351
2352 Faqplugins/helpdesk/business/Faq.html#Faq">Faq faq = new Faq( );
2353 faq.setName( strName );
2354 faq.setDescription( strDescription );
2355 faq.setRoleKey( strRoleKey );
2356 faq.setWorkgroup( strWorkgroupKey );
2357 FaqHome.insert( faq, getPlugin( ) );
2358
2359
2360 return JSP_MANAGE_HELPDESK;
2361 }
2362
2363
2364
2365
2366
2367
2368 public String getModifyFaq( HttpServletRequest request )
2369 {
2370 Faq faq = getAuthorizedFaq( request, FaqResourceIdService.PERMISSION_MODIFY );
2371
2372 if ( faq == null )
2373 {
2374 return getManageHelpdesk( request );
2375 }
2376
2377 HashMap model = new HashMap( );
2378
2379 setPageTitleProperty( MESSAGE_PAGE_TITLE_MODIFY_FAQ );
2380
2381 model.put( MARK_FAQ, faq );
2382 model.put( MARK_PLUGIN, getPlugin( ) );
2383 model.put( MARK_ROLE_KEY_LIST, RoleHome.getRolesList( ) );
2384 model.put( MARK_WORKGROUP_KEY_LIST, AdminWorkgroupService.getUserWorkgroups( getUser( ), getLocale( ) ) );
2385
2386 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MODIFY_FAQ, getLocale( ), model );
2387
2388 return getAdminPage( template.getHtml( ) );
2389 }
2390
2391
2392
2393
2394
2395
2396 public String doModifyFaq( HttpServletRequest request )
2397 {
2398 Faq faq = getAuthorizedFaq( request, FaqResourceIdService.PERMISSION_MODIFY );
2399
2400 if ( faq == null )
2401 {
2402 return AdminMessageService.getMessageUrl( request, MESSAGE_ACCESS_DENIED, AdminMessage.TYPE_STOP );
2403 }
2404
2405 String strName = request.getParameter( PARAMETER_NAME );
2406 String strDescription = request.getParameter( PARAMETER_DESCRIPTION );
2407 String strRoleKey = request.getParameter( PARAMETER_ROLE_KEY );
2408 String strWorkgroupKey = request.getParameter( PARAMETER_WORKGROUP_KEY );
2409
2410
2411 if ( ( faq == null ) || ( strName == null ) || strName.equals( "" ) || ( strDescription == null ) ||
2412 strDescription.equals( "" ) || ( strRoleKey == null ) || ( strWorkgroupKey == null ) )
2413 {
2414 return AdminMessageService.getMessageUrl( request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP );
2415 }
2416
2417
2418 faq.setName( strName );
2419 faq.setDescription( strDescription );
2420 faq.setRoleKey( strRoleKey );
2421 faq.setWorkgroup( strWorkgroupKey );
2422
2423 FaqHome.store( faq, getPlugin( ) );
2424
2425
2426 return JSP_MANAGE_HELPDESK;
2427 }
2428
2429
2430
2431
2432
2433
2434 public String getConfirmRemoveFaq( HttpServletRequest request )
2435 {
2436 Faq faq = getAuthorizedFaq( request, FaqResourceIdService.PERMISSION_DELETE );
2437
2438
2439 if ( ( faq == null ) )
2440 {
2441 return AdminMessageService.getMessageUrl( request, MESSAGE_ACCESS_DENIED, AdminMessage.TYPE_STOP );
2442 }
2443
2444 UrlItem url = new UrlItem( JSP_DO_REMOVE_FAQ );
2445 url.addParameter( PARAMETER_FAQ_ID, faq.getId( ) );
2446
2447 if ( ( faq.getSubjectsList( getPlugin( ) ).size( ) > 0 ) ||
2448 ( faq.getThemesList( getPlugin( ) ).size( ) > 0 ) )
2449 {
2450 return AdminMessageService.getMessageUrl( request, MESSAGE_CANNOT_DELETE_FAQ, AdminMessage.TYPE_STOP );
2451 }
2452
2453 return AdminMessageService.getMessageUrl( request, MESSAGE_CONFIRM_DELETE_FAQ, url.getUrl( ),
2454 AdminMessage.TYPE_CONFIRMATION );
2455 }
2456
2457
2458
2459
2460
2461
2462 public String doRemoveFaq( HttpServletRequest request )
2463 {
2464 Faq faq = getAuthorizedFaq( request, FaqResourceIdService.PERMISSION_DELETE );
2465
2466 if ( ( faq == null ) )
2467 {
2468 return AdminMessageService.getMessageUrl( request, MESSAGE_ACCESS_DENIED, AdminMessage.TYPE_STOP );
2469 }
2470
2471 if ( ( faq.getSubjectsList( getPlugin( ) ).size( ) > 0 ) ||
2472 ( faq.getThemesList( getPlugin( ) ).size( ) > 0 ) )
2473 {
2474 return AdminMessageService.getMessageUrl( request, MESSAGE_CANNOT_DELETE_FAQ, AdminMessage.TYPE_STOP );
2475 }
2476
2477 FaqHome.delete( faq.getId( ), getPlugin( ) );
2478
2479
2480 return JSP_MANAGE_HELPDESK;
2481 }
2482
2483
2484
2485
2486
2487
2488
2489
2490 private int validateSubjectId( String strSubjectId, Faq faq )
2491 {
2492 int nReturn = -1;
2493 AppLogService.debug( "subject id : " + strSubjectId );
2494
2495 if ( !strSubjectId.matches( REGEX_ID ) )
2496 {
2497 return nReturn;
2498 }
2499
2500 int nIdSubject = Integer.parseInt( strSubjectId );
2501 Subject/../../../../../fr/paris/lutece/plugins/helpdesk/business/Subject.html#Subject">Subject subject = (Subject) SubjectHome.getInstance( ).findByPrimaryKey( nIdSubject, getPlugin( ) );
2502
2503 if ( subject == null )
2504 {
2505 return nReturn;
2506 }
2507
2508 while ( subject.getIdParent( ) != 0 )
2509 {
2510 subject = subject.getParent( getPlugin( ) );
2511 }
2512
2513 for ( Subject subjectFaq : faq.getSubjectsList( getPlugin( ) ) )
2514 {
2515 if ( subject.getId( ) == subjectFaq.getId( ) )
2516 {
2517 nReturn = nIdSubject;
2518 }
2519 }
2520
2521 return nReturn;
2522 }
2523
2524
2525
2526
2527
2528
2529
2530
2531 private int validateIdOrder( String strIdOrder, Faq faq )
2532 {
2533 try
2534 {
2535 int nIdOrder = Integer.parseInt( strIdOrder );
2536 return nIdOrder;
2537 }
2538 catch( NumberFormatException e)
2539 {
2540 return -1;
2541 }
2542 }
2543
2544
2545
2546
2547
2548
2549 private String validateQuestion( String strQuestion )
2550 {
2551 AppLogService.debug( "question : " + strQuestion );
2552
2553 if ( strQuestion.equals( "" ) )
2554 {
2555 return null;
2556 }
2557
2558 return strQuestion;
2559 }
2560
2561
2562
2563
2564
2565
2566 private String validateAnswer( String strAnswer )
2567 {
2568 AppLogService.debug( "answer : " + strAnswer );
2569
2570 if ( strAnswer.equals( "" ) )
2571 {
2572 return null;
2573 }
2574
2575 return strAnswer;
2576 }
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587 private String getAdminMessageError( HttpServletRequest request, int nColumnId, String strCsvColumnName,
2588 int nRowNumber )
2589 {
2590 return AdminMessageService.getMessageUrl( request, MESSAGE_CSV_FIELD_ERROR,
2591 new String[] { String.valueOf( nColumnId + 1 ), strCsvColumnName, String.valueOf( nRowNumber + 1 ) },
2592 AdminMessage.TYPE_ERROR );
2593 }
2594
2595
2596
2597
2598
2599
2600
2601 private List<String[]> getRowsFromCsvFile( HttpServletRequest request, boolean isMulti )
2602 {
2603 String strCsvFileExtension = AppPropertiesService.getProperty( PROPERTY_CSV_FILE_EXTENSION,
2604 DEFAULT_CSV_FILE_EXTENSION );
2605 String strCharset = AppPropertiesService.getProperty( PROPERTY_CSV_FILE_CHARSET, DEFAULT_CSV_FILE_CHARSET );
2606 char cImportDelimiter = AppPropertiesService.getProperty( PROPERTY_IMPORT_DELIMITER, DEFAULT_IMPORT_DELIMITER )
2607 .charAt( 0 );
2608
2609 String strMultiFileName = null;
2610 if( isMulti )
2611 {
2612
2613 MultipartHttpServletRequest multi = (MultipartHttpServletRequest) request;
2614
2615 _csvItem = multi.getFile( PARAMETER_CSV_FILE );
2616 }
2617
2618 strMultiFileName = UploadUtil.cleanFileName( _csvItem.getName( ) );
2619
2620 if ( strMultiFileName.equals( "" ) )
2621 {
2622 return null;
2623 }
2624
2625
2626 String strExtension = strMultiFileName.substring( strMultiFileName.length( ) - strCsvFileExtension.length( ),
2627 strMultiFileName.length( ) );
2628
2629 if ( !strExtension.equals( strCsvFileExtension ) )
2630 {
2631 return null;
2632 }
2633
2634 Reader fileReader;
2635 List<String[]> listQuestionAnswers = null;
2636
2637 try
2638 {
2639 fileReader = new InputStreamReader( _csvItem.getInputStream( ), strCharset );
2640
2641 CSVReader csvReader = new CSVReader( fileReader, cImportDelimiter );
2642
2643 listQuestionAnswers = csvReader.readAll( );
2644 }
2645 catch ( IOException e )
2646 {
2647 AppLogService.error( e.getMessage( ) );
2648 throw new RuntimeException( e.getMessage( ) );
2649 }
2650
2651 return listQuestionAnswers;
2652 }
2653
2654
2655
2656
2657
2658
2659
2660
2661 private Faq getAuthorizedFaq( HttpServletRequest request, String strPermissionType )
2662 {
2663 String strIdFaq = request.getParameter( PARAMETER_FAQ_ID );
2664
2665 if ( ( strIdFaq == null ) || !strIdFaq.matches( REGEX_ID ) )
2666 {
2667 return null;
2668 }
2669
2670 int nIdFaq = Integer.parseInt( strIdFaq );
2671 Faq faq = FaqHome.load( nIdFaq, getPlugin( ) );
2672
2673 if ( ( faq == null ) || !AdminWorkgroupService.isAuthorized( faq, getUser( ) ) ||
2674 !RBACService.isAuthorized( Faq.RESOURCE_TYPE, String.valueOf( faq.getId( ) ), strPermissionType,
2675 getUser( ) ) )
2676 {
2677 return null;
2678 }
2679
2680 return faq;
2681 }
2682
2683
2684
2685
2686
2687
2688
2689 private Collection<String> getAuthorizedActionCollection( Faq faq )
2690 {
2691 Collection<String> listActions = new ArrayList<String>( );
2692
2693 if ( RBACService.isAuthorized( Faq.RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID,
2694 FaqResourceIdService.PERMISSION_CREATE, getUser( ) ) )
2695 {
2696 listActions.add( FaqResourceIdService.PERMISSION_CREATE );
2697 }
2698
2699 if ( RBACService.isAuthorized( Faq.RESOURCE_TYPE, String.valueOf( faq.getId( ) ),
2700 FaqResourceIdService.PERMISSION_DELETE, getUser( ) ) )
2701 {
2702 listActions.add( FaqResourceIdService.PERMISSION_DELETE );
2703 }
2704
2705 if ( RBACService.isAuthorized( Faq.RESOURCE_TYPE, String.valueOf( faq.getId( ) ),
2706 FaqResourceIdService.PERMISSION_IMPORT_QUESTIONS_ANSWERS, getUser( ) ) )
2707 {
2708 listActions.add( FaqResourceIdService.PERMISSION_IMPORT_QUESTIONS_ANSWERS );
2709 }
2710
2711 if ( RBACService.isAuthorized( Faq.RESOURCE_TYPE, String.valueOf( faq.getId( ) ),
2712 FaqResourceIdService.PERMISSION_MANAGE_QUESTIONS_ANSWERS, getUser( ) ) )
2713 {
2714 listActions.add( FaqResourceIdService.PERMISSION_MANAGE_QUESTIONS_ANSWERS );
2715 }
2716
2717 if ( RBACService.isAuthorized( Faq.RESOURCE_TYPE, String.valueOf( faq.getId( ) ),
2718 FaqResourceIdService.PERMISSION_MANAGE_SUBJECTS, getUser( ) ) )
2719 {
2720 listActions.add( FaqResourceIdService.PERMISSION_MANAGE_SUBJECTS );
2721 }
2722
2723 if ( RBACService.isAuthorized( Faq.RESOURCE_TYPE, String.valueOf( faq.getId( ) ),
2724 FaqResourceIdService.PERMISSION_MANAGE_THEMES, getUser( ) ) )
2725 {
2726 listActions.add( FaqResourceIdService.PERMISSION_MANAGE_THEMES );
2727 }
2728
2729 if ( RBACService.isAuthorized( Faq.RESOURCE_TYPE, String.valueOf( faq.getId( ) ),
2730 FaqResourceIdService.PERMISSION_MANAGE_VISITOR_QUESTIONS, getUser( ) ) )
2731 {
2732 listActions.add( FaqResourceIdService.PERMISSION_MANAGE_VISITOR_QUESTIONS );
2733 }
2734
2735 if ( RBACService.isAuthorized( Faq.RESOURCE_TYPE, String.valueOf( faq.getId( ) ),
2736 FaqResourceIdService.PERMISSION_MODIFY, getUser( ) ) )
2737 {
2738 listActions.add( FaqResourceIdService.PERMISSION_MODIFY );
2739 }
2740
2741 return listActions;
2742 }
2743
2744
2745 }