... |
... |
@@ -1,8 +1,48 @@ |
1 |
1 |
{{groovy}} |
2 |
|
- |
|
2 |
+ if(!hasAdmin){ |
|
3 |
+ |
|
4 |
+ } |
3 |
3 |
// Nom de l'image en pièce jointe |
4 |
|
-def attachmentName = 'image.gif' |
|
6 |
+def attachmentName = 'NGIZero_logo.png' |
5 |
5 |
|
|
8 |
+// Récupérer l'image en pièce jointe |
|
9 |
+def img = doc.getAttachment(attachmentName) |
6 |
6 |
|
|
11 |
+// Accéder à l'objet et à la propriété 'count' |
|
12 |
+def obj = doc.getObject(doc.toString()) |
|
13 |
+def countProperty = obj.getProperty('count') |
|
14 |
+def countValue = countProperty.value |
|
15 |
+ |
|
16 |
+// Initialiser un compteur pour la date du jour |
|
17 |
+def currentDate = new Date().format('yyyy-MM-dd') |
|
18 |
+def jsonSlurper = new groovy.json.JsonSlurper() |
|
19 |
+def json = countValue ? jsonSlurper.parseText(countValue) : [:] |
|
20 |
+ |
|
21 |
+// Incrémenter le compteur pour la date actuelle |
|
22 |
+if (json.containsKey(currentDate)) { |
|
23 |
+ json[currentDate] += 1 |
|
24 |
+} else { |
|
25 |
+ json[currentDate] = 1 |
|
26 |
+} |
|
27 |
+ |
|
28 |
+// Mettre à jour la propriété 'count' avec le nouveau JSON |
|
29 |
+def jsonOutput = new groovy.json.JsonBuilder(json).toPrettyString() |
|
30 |
+obj.set('count',jsonOutput) |
|
31 |
+doc.save() |
|
32 |
+ |
|
33 |
+if (img != null) { |
|
34 |
+ def outs = response.outputStream |
|
35 |
+ response.setContentType("image/png") |
|
36 |
+ |
|
37 |
+ // Récupérer le contenu de l'image |
|
38 |
+ def imgBytes = img.getContent() |
|
39 |
+ |
|
40 |
+ // Écrire les bytes dans le flux de sortie |
|
41 |
+ outs.write(imgBytes) |
|
42 |
+ outs.close() |
|
43 |
+} else { |
|
44 |
+ response.sendError(404, "L'image n'existe pas.") |
|
45 |
+} |
|
46 |
+ |
7 |
7 |
{{/groovy}} |
8 |
8 |
|