1 /*******************************************************************************
2 * Copyright � Igor Barma, Alexandre Desoubeaux, Christian Martel, Eric Brun, Mathieu Amblard, Gwenael Gevet, Pierre Guillot, 2012
3 * Copyright Alexandre Desoubeaux, Christian Martel, Cedric Lecarpentier, Alexandre Lefevre, Marc Salvat 2014-2016
4 * Copyright Alexandre Desoubeaux, Christian Martel, Cedric Lecarpentier, Marc Salvat, Marc Suarez, Harifetra Ramamonjy 2017
6 * This file is part of the work and learning management system Pentila Nero.
8 * Pentila Nero is free software. You can redistribute it and/or modify since
9 * you respect the terms of either (at least one of the both license) :
10 * - under the terms of the GNU Affero General Public License as
11 * published by the Free Software Foundation, either version 3 of the
12 * License, or (at your option) any later version.
13 * - the CeCILL-C as published by CeCILL-C; either version 1 of the
14 * License, or any later version
15 * - the GNU Lesser General Public License as published by the
16 * Free Software Foundation, either version 3 of the license,
17 * or (at your option) any later version.
19 * There are special exceptions to the terms and conditions of the
20 * licenses as they are applied to this software. View the full text of
21 * the exception in file LICENSE-PROJECT.txt in the directory of this software
24 * Pentila Nero is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * Licenses for more details.
29 * You should have received a copy of the GNU Affero General Public License
30 * and the CeCILL-C and the GNU Lesser General Public License along with
31 * Pentila Nero. If not, see :
32 * <http://www.gnu.org/licenses/> and
33 * <http://www.cecill.info/licences.fr.html>.
34 ******************************************************************************/
35 package com.pentila.entSavoie.cahierDeTexte.util;
37 import java.io.IOException;
38 import java.text.SimpleDateFormat;
39 import java.util.ArrayList;
40 import java.util.Collections;
41 import java.util.Date;
42 import java.util.List;
43 import java.util.Locale;
44 import java.util.ResourceBundle;
46 import javax.portlet.ActionRequest;
48 import com.liferay.portal.kernel.exception.PortalException;
49 import com.liferay.portal.kernel.exception.SystemException;
50 import com.liferay.portal.kernel.json.JSONArray;
51 import com.liferay.portal.kernel.json.JSONFactoryUtil;
52 import com.liferay.portal.kernel.json.JSONObject;
53 import com.liferay.portal.kernel.util.FileUtil;
54 import com.liferay.portal.kernel.util.HttpUtil;
55 import com.liferay.portal.kernel.util.WebKeys;
56 import com.liferay.portal.model.CompanyConstants;
57 import com.liferay.portal.model.Group;
58 import com.liferay.portal.model.Organization;
59 import com.liferay.portal.model.Role;
60 import com.liferay.portal.model.RoleConstants;
61 import com.liferay.portal.model.User;
62 import com.liferay.portal.service.GroupLocalServiceUtil;
63 import com.liferay.portal.service.OrganizationLocalServiceUtil;
64 import com.liferay.portal.service.RoleLocalServiceUtil;
65 import com.liferay.portal.service.UserLocalServiceUtil;
66 import com.liferay.portal.theme.ThemeDisplay;
67 import com.liferay.portlet.documentlibrary.store.DLStoreUtil;
68 import com.pentila.entSavoie.ENTDisplayUtil;
69 import com.pentila.entSavoie.ENTRolesConstants;
70 import com.pentila.entSavoie.cahierDeTexte.model.AnnotationCDT;
71 import com.pentila.entSavoie.cahierDeTexte.model.EventCDT;
72 import com.pentila.entSavoie.cahierDeTexte.model.LockCDT;
73 import com.pentila.entSavoie.cahierDeTexte.model.Matiere;
74 import com.pentila.entSavoie.cahierDeTexte.service.EventCDTLocalServiceUtil;
75 import com.pentila.entSavoie.cahierDeTexte.service.MatiereEtabLocalServiceUtil;
76 import com.pentila.entSavoie.cahierDeTexte.service.MatiereLocalServiceUtil;
77 import com.pentila.entSavoie.directory.OrganizationFinderServiceUtil;
78 import com.pentila.entSavoie.utils.DLEntryUtil;
80 public class ProxyEvent implements Comparable<ProxyEvent>{
82 static SimpleDateFormat testDateFormat = new SimpleDateFormat("yyyyMMdd");
84 static SimpleDateFormat classicDateFormat = new SimpleDateFormat("yyyy-MM-dd");
86 static SimpleDateFormat frenchDateFormat = new SimpleDateFormat("dd/MM/yyyy");
88 static SimpleDateFormat textFrenchDateFormat = new SimpleDateFormat("E dd MMM yyyy", Locale.FRENCH);
90 private User currentUser = null;
93 private Date startDay;
96 private String startEvtTime;
97 private String endEvtTime;
98 private String repeatEvt;
99 private Boolean repeatEvtModified;
100 private Boolean alertFlag;
101 private Boolean locked;
102 private String subject;
103 private String description;
104 private long subjectCDT;
105 private long creator;
106 private long typeEvt;
107 private long kindEvt;
108 private long groupId;
109 private long fromEvt;
111 private Date fromDate;
112 private Boolean wTodo;
113 private Boolean wGave;
114 private Boolean broadcast;
115 private int estimatedTime;
116 private String timeSorted;
117 private long repeatEvtGroup;
118 private boolean visa;
120 // infos permettant de gerer les annotations
121 private Boolean wDone = false;
122 private String annotation = "";
125 public ProxyEvent(EventCDT evt, Long userId, AnnotationCDT anno, List<LockCDT> locks) {
127 setEvtId(evt.getEvtId());
129 setStartDay(evt.getStartDay());
130 setEndDay(evt.getEndDay());
131 setAlertFlag(evt.getAlertFlag());
133 setStartEvtTime(evt.getStartEvtTime());
134 setEndEvtTime(evt.getEndEvtTime());
135 setRepeatEvt(evt.getRepeatEvt());
136 setRepeatEvtModified(evt.getRepeatEvtModified());
137 // pour ne pas être embéter avec les doubles quotes
138 setSubject(evt.getSubject().replace('"', '\''));
140 setSubjectCDT(evt.getSubjectCDT());
141 setCreator(evt.getCreator());
142 setTypeEvt(evt.getTypeEvt());
143 setKindEvt(evt.getKindEvt());
144 setGroupId(evt.getGroupId());
145 setFromDate(evt.getFromDate());
146 setwTodo(evt.getWtodo());
147 setwGave(evt.getWgave());
148 setEstimatedTime(evt.getEstimatedTime());
149 setFromEvt(evt.getFromEvt());
150 setToEvt(evt.getToEvt());
151 setRepeatEvtGroup(evt.getRepeatEvtGroup());
152 setBroadcast(evt.getBroadcast());
154 setTimeSorted(testDateFormat.format(evt.getStartDay())+evt.getStartEvtTime());
157 setwDone(anno.getDone());
158 setAnnotation(anno.getAnnotation().replace('"', '\''));
161 // On traite maintenant le lock des evt
162 // On lock les evt dont on est pas le createur
163 int startEvt = Integer.parseInt(testDateFormat.format(evt.getStartDay()));
166 setCurrentUser(UserLocalServiceUtil.getUser(userId));
167 } catch (Exception e) {
171 if (userId.equals(evt.getCreator())) {
173 for (LockCDT l: locks) {
174 int startLock = Integer.parseInt(testDateFormat.format(l.getStartDay()));
175 int endLock = Integer.parseInt(testDateFormat.format(l.getEndDay()));
177 if ( startEvt >= startLock && startEvt <= endLock ) {
182 setDescription(evt.getDescription().replace('"', '\''));
186 if (getBroadcast()) {
187 setDescription(evt.getDescription().replace('"', '\''));
194 setVisa(evt.getVisa());
197 public JSONObject getJSONEvent(ActionRequest actionRequest, ResourceBundle messages) throws PortalException, SystemException {
198 ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
199 return getJSONEvent(false, null, themeDisplay, messages);
202 public JSONObject getJSONEvent(boolean addInfos, User user, ActionRequest actionRequest, ResourceBundle messages) throws PortalException, SystemException {
203 ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
204 return getJSONEvent(addInfos, user, themeDisplay, messages);
209 * indique les calendriers que l'on souhaite: all / cours / devoirs
211 * @throws SystemException
212 * @throws PortalException
213 * @throws IOException
215 public JSONObject getJSONEvent(boolean addInfos, User user, ThemeDisplay themeDisplay, ResourceBundle messages) throws PortalException, SystemException {
217 Role enseignant = RoleLocalServiceUtil.getRole(user.getCompanyId(), ENTRolesConstants.NATIONAL_3);
218 Role principal = RoleLocalServiceUtil.getRole(user.getCompanyId(), ENTRolesConstants.NATIONAL_4);
219 Role admin = RoleLocalServiceUtil.getRole(user.getCompanyId(), RoleConstants.ADMINISTRATOR);
221 List<Role> lroles = user.getRoles();
223 boolean isEnseignant = false;
225 if(lroles.contains(enseignant)){
229 boolean isPrincipalOrAdmin = RoleLocalServiceUtil.hasUserRole(user.getUserId(), principal.getRoleId()) ||
230 RoleLocalServiceUtil.hasUserRole(user.getUserId(), admin.getRoleId());
233 JSONObject event = JSONFactoryUtil.createJSONObject();
234 event.put("id", getEvtId());
235 event.put("ymd", classicDateFormat.format(getStartDay()));
236 event.put("eymd", classicDateFormat.format(getEndDay()));
238 String color = "blue";
240 Matiere myMatiere = null;
241 long myMatiereId = 0;
242 String myMatiereLabel = messages.getString("matiere-non-definie");
244 myMatiere = MatiereLocalServiceUtil.getMatiere(getSubjectCDT());
245 myMatiereId = myMatiere.getMatiereId();
246 myMatiereLabel = myMatiere.getLabelLong().toLowerCase();
247 long etabId = OrganizationFinderServiceUtil.getEtabRatachement(user).getOrganizationId();
248 color = MatiereEtabLocalServiceUtil.getMatiereEtabByEtabIdMatiereId(etabId, myMatiere.getMatiereId()).getColor();
249 } catch (Exception e) {}
250 event.put("color", color);
251 User creatorUser = null;
252 String creatorName = "";
254 creatorUser = UserLocalServiceUtil.getUser(getCreator());
255 creatorName = CDTUserSettings.getUserName(creatorUser);
256 } catch (Exception e) {
259 event.put("startTime", getStartEvtTime());
260 event.put("endTime", getEndEvtTime());
261 event.put("subject", getSubject());
262 event.put("description", getDescription());
263 event.put("alertFlag", getAlertFlag());
264 event.put("broadcast", getBroadcast());
266 if (getKindEvt()==1) {
267 event.put("locked", getLocked());
269 event.put("locked", true);
272 // - ------- - - ------- - - ------- - - ------- - - ------- -
273 //Patch for old event
274 if (!getRepeatEvt().equals("no")) {
276 JSONObject repeatEvtJS = JSONFactoryUtil.createJSONObject(getRepeatEvt());
278 if (!repeatEvtJS.has("endDay")) {
280 if (repeatEvtJS.has("rtime")) {
281 repeatEvtJS.put("endDay", "no");
285 List<EventCDT> linkedEvents = EventCDTLocalServiceUtil.getEventCDTLinked(getRepeatEvtGroup(), false);
286 Date evtEndDate = getEndDay();
287 for (EventCDT eventCDT : linkedEvents) {
288 if (evtEndDate.before(eventCDT.getEndDay())) {
289 evtEndDate = eventCDT.getEndDay();
292 repeatEvtJS.put("endDay", classicDateFormat.format(evtEndDate));
295 EventCDT currentEvent = EventCDTLocalServiceUtil.getEventCDT(evtId);
296 currentEvent.setRepeatEvt(repeatEvtJS.toString());
297 setRepeatEvt(repeatEvtJS.toString());
299 EventCDTLocalServiceUtil.updateEventCDT(currentEvent);
304 // - ------- - - ------- - - ------- - - ------- - - ------- -
306 event.put("repeatType", getRepeatEvt());
307 event.put("repeatEvtModified", getRepeatEvtModified());
308 event.put("matiereId", myMatiereId);
309 String matiereLabel = myMatiereLabel;
310 event.put("kindEvtId", getKindEvt());
311 if (getKindEvt()==1) {
312 event.put("kindEvtLabel", messages.getString("cours"));
314 event.put("kindEvtLabel", messages.getString("devoir"));
316 event.put("fromEvt", String.valueOf(getFromEvt()));
317 event.put("toEvt", String.valueOf(getToEvt()));
318 event.put("estimatedTime", getEstimatedTime());
320 event.put("timeSorted", getTimeSorted());
322 event.put("wDone", getwDone());
323 event.put("annotation", getAnnotation());
325 event.put("creatorName", creatorName);
326 event.put("creatorId", creatorUser.getUserId());
328 event.put("calendarId", String.valueOf(getGroupId()));
330 String classeName = "";
332 // on place le nom de la classe au cas ou la personne ne l'a pas dans sa liste de classe
333 Group grpTemp = GroupLocalServiceUtil.getGroup(getGroupId());
335 if (grpTemp.isOrganization()) {
336 Organization o = OrganizationLocalServiceUtil.getOrganization(grpTemp.getOrganizationId());
337 classeName = ENTDisplayUtil.formatSCONETName(user, o.getName(), false);
341 classeName = grpTemp.getName();
344 catch(Exception exc) {
345 classeName = "Classe non trouvee";
348 event.put("classeName", classeName);
352 final JSONArray attachements = JSONFactoryUtil.createJSONArray();
353 String[] attachementsFiles = null;
355 if (getBroadcast() || user.getUserId() == getCreator()) {
357 // Traitement du retour pour les pieces jointes
359 attachementsFiles = EventCDTLocalServiceUtil.getAttachFilesNameToEventCDT(user.getCompanyId(), getEvtId());
360 for (int i = 0; i < attachementsFiles.length; i++) {
361 final JSONObject fileDescriptor = JSONFactoryUtil.createJSONObject();
362 String fileName = FileUtil.getShortFileName(attachementsFiles[i]);
363 long fileSize = DLStoreUtil.getFileSize(user.getCompanyId(), CompanyConstants.SYSTEM, attachementsFiles[i])/1000;
369 String[] splitFN = DLEntryUtil.splitFileName(fileName);
370 //String originalTitle = splitFN[0];
371 String extension = splitFN[1];
373 String fileId = attachementsFiles[i];
374 Date now = new Date();
375 String tokenId = fileId + now.getTime();
377 boolean isSignet = false;
378 String urlSignet = "";
379 if(extension.contains("html")){
380 isSignet = DLEntryUtil.isSignetFile(DLStoreUtil.getFileAsStream(user.getCompanyId(), CompanyConstants.SYSTEM, attachementsFiles[i]));
382 urlSignet = DLEntryUtil.getUrlSignet(DLStoreUtil.getFileAsStream(user.getCompanyId(), CompanyConstants.SYSTEM, attachementsFiles[i]));
386 if (themeDisplay != null) {
388 href = "<a id='" + tokenId + "' style='cursor:pointer;' onClick='showMenuAttachment(""+ themeDisplay.getPathMain()+"/cahier_de_texte/get_event_attachment?evtId="+ getEvtId() +"&companyId="+ user.getCompanyId() +"&attachment="+HttpUtil.encodeURL(fileName)+"","" + fileId + "","" + fileName + "","" + extension + "","" + fileSize + "","" + getEvtId() + "","" + tokenId + "","" + urlSignet + "");'>"+fileName + " (" + fileSize + " kb)" +"</a>";
390 href += " - <a id='" + tokenId + "' style='cursor:pointer;' onClick='showMenuAttachment(""+ themeDisplay.getPathMain()+"/cahier_de_texte/get_event_attachment?evtId="+ getEvtId() +"&companyId="+ user.getCompanyId() +"&attachment="+HttpUtil.encodeURL(fileName)+"","" + fileId + "","" + fileName + "","" + extension + "","" + fileSize + "","" + getEvtId() + "","" + tokenId + "","" + urlSignet + "");'>"+fileName + " (" + fileSize + " kb)" +"</a>";
392 fileDescriptor.put("fileHref", "<a id='" + tokenId + "' style='cursor:pointer;' onClick='showMenuAttachment(""+ themeDisplay.getPathMain()+"/cahier_de_texte/get_event_attachment?evtId="+ getEvtId() +"&companyId="+ user.getCompanyId() +"&attachment="+HttpUtil.encodeURL(fileName)+"","" + fileId + "","" + fileName + "","" + extension + "","" + fileSize + "","" + getEvtId() + "","" + tokenId + "","" + urlSignet + "");'>"+fileName + " (" + fileSize + " kb)" +"</a>");
395 fileDescriptor.put("fileHref", "");
397 fileDescriptor.put("fileId", fileId);
398 fileDescriptor.put("fileName", fileName);
399 fileDescriptor.put("fileInfo", fileSize);
400 fileDescriptor.put("type", "Fichier");
401 fileDescriptor.put("isSignet", isSignet);
402 attachements.put(fileDescriptor);
405 event.put("attachments", attachements.toString());
407 // Si l'event comporte des pieces jointes
408 if (attachementsFiles.length>0) {
409 event.put("evtAttachFiles", true);
411 event.put("evtAttachFiles", false);
415 event.put("attachments", attachements.toString());
416 event.put("evtAttachFiles", false);
419 String infosEvt = "";
425 final JSONArray attachmentsDevoir = JSONFactoryUtil.createJSONArray();
427 Boolean attachDevoir = false;
429 boolean hasDevoirToDo = false;
431 String devoirToDo = "";
437 if (getKindEvt() == 1) {
438 if(getCreator()!=user.getUserId()){
439 //infosEvt = "<div class='detailsPlannigView'> <div class='matiereLabelPlannigView'> " + messages.getString("cours-de") + " "+ matiereLabel + " " + messages.getString("donne-par") + " " + creatorName + "</div>";
440 infosEvt = "<div class='detailsPlannigView'> <div class='matiereLabelPlannigView'> " + messages.getString("donne-par") + " " + creatorName + "</div>";
442 boolean hasSubject = !getSubject().isEmpty();
443 boolean hasDesc = !getDescription().isEmpty();
445 infosEvt += "<b>" + getSubject() + "</b>";
449 infosEvt += ": " + getDescription();
452 infosEvt += getDescription();
455 if (hasDesc || hasSubject) {
456 infosEvt += "<br />";
459 /*if (!getAnnotation().isEmpty()) {
460 infosEvt += "<b>" + messages.getString("note") + ": </b>" + getAnnotation() + "<br />";
462 if (attachementsFiles != null && attachementsFiles.length>0) {
463 infosEvt += "<u> " + messages.getString("piece-jointe") + " :</u> " + href + "<br />";
465 // Traitement des devoirs
466 List<EventCDT> evtCDTDevoirToDo = EventCDTLocalServiceUtil.getToEventCDT(evtId);
467 List<EventCDT> filteredEventToDo = new ArrayList<EventCDT>();
469 List<EventCDT> evtCDTDevoirFrom = new ArrayList<EventCDT>();
470 // si c'est un enseignant, on prend les devoirs donnes et a rendre
471 if (RoleLocalServiceUtil.hasUserRole(user.getUserId(), user.getCompanyId(), ENTRolesConstants.NATIONAL_3, false) || true) {
472 evtCDTDevoirFrom.addAll(EventCDTLocalServiceUtil.getFromEventCDT(evtId));
474 if (user.getUserId() != getCreator()) {
476 for (EventCDT devoirARendre : evtCDTDevoirToDo) {
477 if (devoirARendre.getBroadcast()) {
478 filteredEventToDo.add(devoirARendre);
483 filteredEventToDo.addAll(evtCDTDevoirToDo);
486 Collections.sort(filteredEventToDo);
487 Collections.sort(evtCDTDevoirFrom);
489 if (!filteredEventToDo.isEmpty()) {
491 hasDevoirToDo = true;
493 // si c'est un enseignant, on prend les devoirs donnes
494 devoir = "<br /><b>" + messages.getString("travail-a-faire-pour-cette-seance")+ ": </b><br />";
495 for (EventCDT todo : filteredEventToDo) {
496 //devoir += " - " + messages.getString("devoir-de") + " " + matiereLabel + " " + messages.getString("donne-par") + " " + creatorName + "<br />";
498 boolean hasDevoirSubject = !todo.getSubject().isEmpty();
499 boolean hasDevoirDesc = !todo.getDescription().isEmpty();
500 if (hasDevoirSubject) {
501 devoir += " <b>" + todo.getSubject().replace('"', '\'') + "</b>";
503 if(todo.getIdCampagne() != 0 && todo.getEtat() == 2){
504 devoir += "<a href=\"https://193.48.120.88/EvalComp/EvalCompPeda.jsp\" target=\"_blank\" style='margin: 0px 0px 0px 40px !important;'>Une évaluation sur EMaEval est en cours</a>";
507 if (hasDevoirSubject) {
508 devoir += ": <br />" + "<p style='margin: 0px 0px 0px 40px !important;'>" + todo.getDescription().replace('"', '\'') + "</p>";
511 devoir += "<p style='margin: 0px 0px 0px 40px !important;'>" + todo.getDescription().replace('"', '\'') + "</p>";
514 if (!hasDevoirDesc) {
518 /*if (todo.getEstimatedTime()>0) {
519 devoir += " " + messages.getString("temps-estime") + ": " + todo.getEstimatedTime() + "mn<br />";
521 /*List<AnnotationCDT> listAnnotation = AnnotationCDTLocalServiceUtil.getAnnotationCDTbyEvt(todo.getEvtId());
522 if (!listAnnotation.isEmpty()) {
523 devoir += " <b>" + messages.getString("note") + ": </b>";
524 for (AnnotationCDT annotation: listAnnotation) {
525 devoir += annotation.getAnnotation().replace('"', '\'') + "<br />";
527 if(annotation.getDone()) {
528 devoir += " " + messages.getString("travail-realise") + " <br />";
530 devoir += " " + messages.getString("travail-non-realise") + " <br />";
535 String[] devoirAttachementsFiles = EventCDTLocalServiceUtil.getAttachFilesNameToEventCDT(getCurrentUser().getCompanyId(), todo.getEvtId());
536 if (devoirAttachementsFiles.length>0) {
539 String hrefDevoir = "";
540 for (int i = 0; i < devoirAttachementsFiles.length; i++) {
541 final JSONObject fileDescriptor = JSONFactoryUtil.createJSONObject();
542 String fileName = FileUtil.getShortFileName(devoirAttachementsFiles[i]);
543 long fileSize = DLStoreUtil.getFileSize(user.getCompanyId(), CompanyConstants.SYSTEM, devoirAttachementsFiles[i])/1000;
549 String[] splitFN = DLEntryUtil.splitFileName(fileName);
550 //String originalTitle = splitFN[0];
551 String extension = splitFN[1];
553 String fileId = devoirAttachementsFiles[i];
554 Date now = new Date();
555 String tokenId = fileId + now.getTime();
557 boolean isSignet = false;
558 String urlSignet = "";
559 if(extension.contains("html")){
560 isSignet = DLEntryUtil.isSignetFile(DLStoreUtil.getFileAsStream(user.getCompanyId(), CompanyConstants.SYSTEM, devoirAttachementsFiles[i]));
561 urlSignet = DLEntryUtil.getUrlSignet(DLStoreUtil.getFileAsStream(user.getCompanyId(), CompanyConstants.SYSTEM, devoirAttachementsFiles[i]));
563 if (themeDisplay != null) {
564 if(hrefDevoir.isEmpty()){
565 hrefDevoir = "<a id='" + tokenId + "' style='cursor:pointer;' onClick='showMenuAttachment(""+ themeDisplay.getPathMain()+"/cahier_de_texte/get_event_attachment?evtId="+ todo.getEvtId() +"&companyId="+ user.getCompanyId() +"&attachment="+HttpUtil.encodeURL(fileName)+"","" + fileId + "","" + fileName + "","" + extension + "","" + fileSize + "","" + todo.getEvtId() + "","" + tokenId + "","" + urlSignet + "");'>"+fileName + " (" + fileSize + " kb)" +"</a>";
567 hrefDevoir += " - <a id='" + tokenId + "' style='cursor:pointer;' onClick='showMenuAttachment(""+ themeDisplay.getPathMain()+"/cahier_de_texte/get_event_attachment?evtId="+ todo.getEvtId() +"&companyId="+ user.getCompanyId() +"&attachment="+HttpUtil.encodeURL(fileName)+"","" + fileId + "","" + fileName + "","" + extension + "","" + fileSize + "","" + todo.getEvtId() + "","" + tokenId + "","" + urlSignet + "");'>"+fileName + " (" + fileSize + " kb)" +"</a>";
569 fileDescriptor.put("fileHref", "<a id='" + tokenId + "' style='cursor:pointer;' onClick='showMenuAttachment(""+ themeDisplay.getPathMain()+"/cahier_de_texte/get_event_attachment?evtId="+ todo.getEvtId() +"&companyId="+ user.getCompanyId() +"&attachment="+HttpUtil.encodeURL(fileName)+"","" + fileId + "","" + fileName + "","" + extension + "","" + fileSize + "","" + todo.getEvtId() + "","" + tokenId + "","" + urlSignet + "");'>"+fileName + " (" + fileSize + " kb)" +"</a>");
572 fileDescriptor.put("fileHref", "");
574 fileDescriptor.put("fileId", fileId);
575 fileDescriptor.put("fileName", fileName);
576 fileDescriptor.put("fileInfo", fileSize);
577 fileDescriptor.put("type", "Fichier");
578 fileDescriptor.put("isSignet", isSignet);
579 attachements.put(fileDescriptor);
581 if (devoirAttachementsFiles.length>0) {
582 devoir += " <u> " + messages.getString("piece-jointe") + " :</u> " + hrefDevoir;
586 //on ajoute aux devoirs à rendre et on enleve le <br />
587 devoirToDo = devoir.substring(6);
590 if ((getBroadcast() || user.getUserId() == getCreator()) && !evtCDTDevoirFrom.isEmpty()) {
591 devoir = "<br /><b>" + messages.getString("devoirs-donnes") + ": </b><br />";
592 for (EventCDT from : evtCDTDevoirFrom) {
593 //devoir += " - " + messages.getString("devoir-de") + " " + matiereLabel + " " + messages.getString("a-rendre-pour-le") + " " + (new SimpleDateFormat("EEEE dd MMM yyyy", user.getLocale())).format(from.getStartDay()) + "<br />";
594 devoir += " - " + messages.getString("a-rendre-pour-le") + " " + (new SimpleDateFormat("EEEE dd MMM yyyy", user.getLocale())).format(from.getStartDay()) + "<br />";
596 boolean hasDevoirSubject = !from.getSubject().isEmpty();
597 boolean hasDevoirDesc = !from.getDescription().isEmpty();
598 if (hasDevoirSubject) {
599 devoir += " <b>" + from.getSubject().replace('"', '\'') + "</b>";
602 if (hasDevoirSubject) {
603 devoir += ": <br />" + "<p style='margin: 0px 0px 0px 40px !important;'>" + from.getDescription().replace('"', '\'') + "</p>";
606 devoir += "<p style='margin: 0px 0px 0px 40px !important;'>" + from.getDescription().replace('"', '\'') + "</p>";
609 if (!hasDevoirDesc) {
613 /*if (from.getEstimatedTime()>0) {
614 devoir += " " + messages.getString("temps-estime") + ": " + from.getEstimatedTime() + messages.getString("minutes") +"<br />";
616 /*List<AnnotationCDT> listAnnotation = AnnotationCDTLocalServiceUtil.getAnnotationCDTbyEvt(from.getEvtId());
617 if (!listAnnotation.isEmpty()) {
618 devoir += " <b>" + messages.getString("note") + ": </b>";
619 for (AnnotationCDT annotation: listAnnotation) {
620 devoir += annotation.getAnnotation().replace('"', '\'') + "<br />";
622 if(annotation.getDone()) {
623 devoir += " " + messages.getString("travail-realise") + " <br />";
625 devoir += " " + messages.getString("travail-non-realise") + " <br />";
630 String[] devoirAttachementsFiles = EventCDTLocalServiceUtil.getAttachFilesNameToEventCDT(getCurrentUser().getCompanyId(), from.getEvtId());
631 if (devoirAttachementsFiles.length>0) {
634 String hrefDevoir = "";
635 for (int i = 0; i < devoirAttachementsFiles.length; i++) {
636 final JSONObject fileDescriptor = JSONFactoryUtil.createJSONObject();
637 String fileName = FileUtil.getShortFileName(devoirAttachementsFiles[i]);
638 long fileSize = DLStoreUtil.getFileSize(user.getCompanyId(), CompanyConstants.SYSTEM, devoirAttachementsFiles[i])/1000;
644 String[] splitFN = DLEntryUtil.splitFileName(fileName);
645 //String originalTitle = splitFN[0];
646 String extension = splitFN[1];
648 String fileId = devoirAttachementsFiles[i];
649 Date now = new Date();
650 String tokenId = fileId + now.getTime();
652 boolean isSignet = false;
653 String urlSignet = "";
654 if(extension.contains("html")){
655 isSignet = DLEntryUtil.isSignetFile(DLStoreUtil.getFileAsStream(user.getCompanyId(), CompanyConstants.SYSTEM, devoirAttachementsFiles[i]));
656 urlSignet = DLEntryUtil.getUrlSignet(DLStoreUtil.getFileAsStream(user.getCompanyId(), CompanyConstants.SYSTEM, devoirAttachementsFiles[i]));
659 if (themeDisplay != null) {
660 if(hrefDevoir.isEmpty()){
661 hrefDevoir += "<a id='" + tokenId + "' style='cursor:pointer;' onClick='showMenuAttachment(""+ themeDisplay.getPathMain()+"/cahier_de_texte/get_event_attachment?evtId="+ from.getEvtId() +"&companyId="+ user.getCompanyId() +"&attachment="+HttpUtil.encodeURL(fileName)+"","" + fileId + "","" + fileName + "","" + extension + "","" + fileSize + "","" + from.getEvtId() + "","" + tokenId + "","" + urlSignet + "");'>"+fileName + " (" + fileSize + " kb)" +"</a>";
663 hrefDevoir += " - <a id='" + tokenId + "' style='cursor:pointer;' onClick='showMenuAttachment(""+ themeDisplay.getPathMain()+"/cahier_de_texte/get_event_attachment?evtId="+ from.getEvtId() +"&companyId="+ user.getCompanyId() +"&attachment="+HttpUtil.encodeURL(fileName)+"","" + fileId + "","" + fileName + "","" + extension + "","" + fileSize + "","" + from.getEvtId() + "","" + tokenId + "","" + urlSignet + "");'>"+fileName + " (" + fileSize + " kb)" +"</a>";
665 fileDescriptor.put("fileHref", "<a id='" + tokenId + "' style='cursor:pointer;' onClick='showMenuAttachment(""+ themeDisplay.getPathMain()+"/cahier_de_texte/get_event_attachment?evtId="+ from.getEvtId() +"&companyId="+ user.getCompanyId() +"&attachment="+HttpUtil.encodeURL(fileName)+"","" + fileId + "","" + fileName + "","" + extension + "","" + fileSize + "","" + from.getEvtId() + "","" + tokenId + "","" + urlSignet + "");'>"+fileName + " (" + fileSize + " kb)" +"</a>");
668 fileDescriptor.put("fileHref", "");
670 fileDescriptor.put("fileId", fileId);
671 fileDescriptor.put("fileName", fileName);
672 fileDescriptor.put("fileInfo", fileSize);
673 fileDescriptor.put("type", "Fichier");
674 fileDescriptor.put("isSignet", isSignet);
675 attachements.put(fileDescriptor);
677 if (devoirAttachementsFiles.length>0) {
678 devoir += " <u> " + messages.getString("piece-jointe") + " :</u> " + hrefDevoir;
684 infosEvt += "</div>";
687 // on récupère le cours auquel est rattaché le devoir
688 if(getToEvt() != 0) {
689 EventCDT toEvt = EventCDTLocalServiceUtil.getEventCDT(getToEvt());
690 toEvent = "<br /> " + toEvt.getSubject().replace('"', '\'') + " " + messages.getString("de") + " " + toEvt.getStartEvtTime() + " " + messages.getString("a") + " " + toEvt.getEndEvtTime() + " " + messages.getString("le") + " " + (new SimpleDateFormat("EEEE dd MMM yyyy", user.getLocale())).format(toEvt.getStartDay()) + ".";
692 toEvent = "<br /> " + getSubject().replace('"', '\'') + " " + messages.getString("de") + " " + getStartEvtTime() + " " + messages.getString("a") + " " + getEndEvtTime() + messages.getString("le") + " " + (new SimpleDateFormat("EEEE dd MMM yyyy", user.getLocale())).format(getStartDay()) + ".";
695 //infosEvt = "<div class='detailsPlannigView'> <div class='matiereLabelPlannigView'> " + messages.getString("devoir-de") + " "+ matiereLabel + " " + messages.getString("donne-par") + " " + creatorName + "</div>";
696 if(getCreator() != user.getUserId()){
697 infosEvt = "<div class='detailsPlannigView'> <div class='matiereLabelPlannigView'> " + messages.getString("donne-par") + " " + creatorName + "</div>";
701 boolean hasSubject = !getSubject().isEmpty();
702 boolean hasDesc = !getDescription().isEmpty();
704 EventCDT fromEvent = EventCDTLocalServiceUtil.getEventCDT(getFromEvt());
705 infosEvt += messages.getString("donne-le2") + " " + (new SimpleDateFormat("EEEE dd MMM yyyy", user.getLocale())).format(fromEvent.getStartDay()) + " <br />";
708 infosEvt += "<b>" + getSubject() + "</b>";
712 infosEvt += ": " + getDescription();
715 infosEvt += getDescription();
718 if (hasDesc || hasSubject) {
719 infosEvt += "<br />";
722 /*if (getEstimatedTime()>0) {
723 infosEvt += messages.getString("temps-estime") + ": " + getEstimatedTime() + messages.getString("minutes") +"<br />";
725 /*if (!getAnnotation().isEmpty()) {
726 infosEvt += messages.getString("note") + ": " + getAnnotation() + "<br />";
730 infosEvt += messages.getString("travail-realise");
733 infosEvt += messages.getString("travail-non-realise");
736 if (attachementsFiles != null && attachementsFiles.length>0) {
737 infosEvt += "<br /> <u> " + messages.getString("piece-jointe") + " :</u> " + href;
739 infosEvt += "</div>";
744 event.put("matiereLabel", matiereLabel);
746 event.put("infosEvt", infosEvt);
748 event.put("evtDevoirToLesson", devoirToDo);
750 event.put("hasDevoirToDo", hasDevoirToDo);
752 event.put("attachmentsDevoir", attachmentsDevoir.toString());
754 event.put("hasAttachmentsDevoir", attachDevoir);
756 event.put("toEvent", toEvent);
758 // L'edition ou la suppression d'un evt n'est possible que pour le createur de l'evt
759 // Ou si l'evenement n'est pas visa
761 boolean hasRight = hasEventRights(getCurrentUser(), getKindEvt(), creatorUser.getUserId(), isVisa());
762 event.put("hideIconBroadcast", !hasRight);
763 event.put("hideIconEdit", !hasRight);
764 event.put("hideIconDelete", !hasRight);
765 event.put("hideIconAddDevoir", !hasRight);
768 if (getKindEvt()==1) {
769 if (creatorUser.getUserId()==getCurrentUser().getUserId()) {
771 event.put("hasVisa", true);
773 event.put("hasVisa", false);
776 event.put("hasVisa", isPrincipalOrAdmin?isVisa():false);
779 event.put("hasVisa", false);
786 public static boolean hasEventRights(User user, long kindEvt, long creatorId, boolean hasVisa){
787 boolean hasRight = false;
789 if (creatorId==user.getUserId()) {
798 public long getEvtId() {
802 public void setEvtId(long evtId) {
806 public String getStartEvtTime() {
810 public void setStartEvtTime(String startEvtTime) {
811 this.startEvtTime = startEvtTime;
814 public String getEndEvtTime() {
818 public void setEndEvtTime(String endEvtTime) {
819 this.endEvtTime = endEvtTime;
822 public Boolean getLocked() {
826 public void setLocked(Boolean locked) {
827 this.locked = locked;
830 public String getSubject() {
834 public void setSubject(String subject) {
835 this.subject = subject;
838 public String getDescription() {
842 public void setDescription(String description) {
843 this.description = description;
846 public long getCreator() {
850 public void setCreator(long creator) {
851 this.creator = creator;
854 public long getTypeEvt() {
858 public void setTypeEvt(long typeEvt) {
859 this.typeEvt = typeEvt;
862 public long getKindEvt() {
866 public void setKindEvt(long kindEvt) {
867 this.kindEvt = kindEvt;
870 public long getGroupId() {
874 public void setGroupId(long groupId) {
875 this.groupId = groupId;
878 public long getFromEvt() {
882 public void setFromEvt(long fromEvt) {
883 this.fromEvt = fromEvt;
886 public long getToEvt() {
890 public void setToEvt(long toEvt) {
894 public Date getFromDate() {
898 public void setFromDate(Date fromDate) {
899 this.fromDate = fromDate;
902 public Boolean getwTodo() {
906 public void setwTodo(Boolean wTodo) {
910 public Boolean getwGave() {
914 public void setwGave(Boolean wGave) {
918 public int getEstimatedTime() {
919 return estimatedTime;
922 public void setEstimatedTime(int estimatedTime) {
923 this.estimatedTime = estimatedTime;
926 public Date getStartDay() {
930 public void setStartDay(Date startDay) {
931 this.startDay = startDay;
934 public Date getEndDay() {
938 public void setEndDay(Date endDay) {
939 this.endDay = endDay;
942 public String getRepeatEvt() {
946 public void setRepeatEvt(String repeatEvt) {
947 this.repeatEvt = repeatEvt;
950 public Boolean getAlertFlag() {
954 public void setAlertFlag(Boolean alertFlag) {
955 this.alertFlag = alertFlag;
958 public Boolean getRepeatEvtModified() {
959 return repeatEvtModified;
962 public void setRepeatEvtModified(Boolean repeatEvtModified) {
963 this.repeatEvtModified = repeatEvtModified;
966 public long getSubjectCDT() {
970 public void setSubjectCDT(long subjectCDT) {
971 this.subjectCDT = subjectCDT;
974 public Boolean getwDone() {
978 public void setwDone(Boolean wDone) {
982 public String getAnnotation() {
986 public void setAnnotation(String annotation) {
987 this.annotation = annotation;
990 public User getCurrentUser() {
994 public void setCurrentUser(User currentUser) {
995 this.currentUser = currentUser;
998 public String getTimeSorted() {
1002 public void setTimeSorted(String timeSorted) {
1003 this.timeSorted = timeSorted;
1006 public long getRepeatEvtGroup() {
1007 return repeatEvtGroup;
1010 public void setRepeatEvtGroup(long repeatEvtGroup) {
1011 this.repeatEvtGroup = repeatEvtGroup;
1014 public Boolean getBroadcast() {
1018 public void setBroadcast(Boolean broadcast) {
1019 this.broadcast = broadcast;
1022 public boolean isVisa() {
1026 public void setVisa(boolean visa) {
1030 public int compareTo(ProxyEvent arg0) {
1031 return this.getTimeSorted().compareTo(arg0.getTimeSorted());