Version brouillon qui marche à peu près
This commit is contained in:
parent
ad8fb596c9
commit
e135d41338
11
README.md
11
README.md
@ -1,3 +1,12 @@
|
|||||||
# paheko-module-votes
|
# paheko-module-votes
|
||||||
|
|
||||||
Module pour le logiciel Paheko permettant de faire voter les utilisateurs.
|
Module pour le logiciel Paheko permettant de faire voter les utilisateurs.
|
||||||
|
|
||||||
|
|
||||||
|
## To Do List
|
||||||
|
|
||||||
|
[x] Permettre et comptabiliser les votes
|
||||||
|
[ ] Régler les droits d'accès
|
||||||
|
[ ] Permettre plusieurs questions par scrutin
|
||||||
|
[ ] Vérifier qu'un utilisateur ne puisse pas voter s'il arrive sur la page de vote en trichant (pour le moment, la page est juste cachée)
|
||||||
|
[ ] Afficher les résultats de façon moins moche
|
||||||
|
17
delete.html
Normal file
17
delete.html
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
{{#restrict section="accounting" level="write" block=true}}{{/restrict}}
|
||||||
|
|
||||||
|
{{#load assign="scrutin" id=$_GET.id|intval}}
|
||||||
|
{{else}}
|
||||||
|
{{:error message="Aucun modèle trouvé"}}
|
||||||
|
{{/load}}
|
||||||
|
|
||||||
|
{{#form on="delete"}}
|
||||||
|
{{:delete id=$scrutin.id}}
|
||||||
|
{{:redirect to="./"}}
|
||||||
|
{{/form}}
|
||||||
|
|
||||||
|
{{:admin_header title="Supprimer scrutin"}}
|
||||||
|
|
||||||
|
{{:delete_form legend="Supprimer un scrutin" warning="Supprimer le scrutin '%s' ?"|args:$scrutin.name}}
|
||||||
|
|
||||||
|
{{:admin_footer}}
|
37
edit.html
Normal file
37
edit.html
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
{{#restrict section="accounting" level="write" block=true}}{{/restrict}}
|
||||||
|
{{:admin_header title="Nouveau scrutin"}}
|
||||||
|
|
||||||
|
{{if $_GET.id}}
|
||||||
|
{{#load assign="scrutin" id=$_GET.id|intval}}{{/load}}
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
|
{{if $_POST.save}}
|
||||||
|
{{:save id=$scrutin.id
|
||||||
|
validate_schema="./scrutin.schema.json"
|
||||||
|
name=$_POST.name|strval|trim
|
||||||
|
desc=$_POST.desc|strval|or:null
|
||||||
|
activity_see=$_POST.activity_see|intval|or:null
|
||||||
|
question=$_POST.question|strval|trim
|
||||||
|
votes=$_POST.votes
|
||||||
|
}}
|
||||||
|
{{:redirect to="./"}}
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
|
<form method="post" action="">
|
||||||
|
<fieldset>
|
||||||
|
<legend>{{if !$scrutin}}Nouveau scrutin{{else}}Modifier le scrutin{{/if}}</legend>
|
||||||
|
<dl>
|
||||||
|
{{:input type="text" required=true name="name" label="Nom du scrutin" source=$scrutin}}
|
||||||
|
{{:input type="text" name="desc" label="Description" source=$scrutin}}
|
||||||
|
{{:input type="text" name="activity_see" label="ID de l'activité requise pour voir le scrutin" help="Laisser vide si tout le monde doit pouvoir voir le scrutin." target="!services/selector.php" source=$scrutin}}
|
||||||
|
{{:input type="text" required=true name="question" label="Question posée" source=$scrutin}}
|
||||||
|
</dl>
|
||||||
|
</fieldset>
|
||||||
|
|
||||||
|
|
||||||
|
<p class="submit">
|
||||||
|
{{:button type="submit" shape="right" label="Enregistrer" name="save" class="main"}}
|
||||||
|
</p>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
{{:admin_footer}}
|
1
icon.svg
Normal file
1
icon.svg
Normal file
@ -0,0 +1 @@
|
|||||||
|
<svg id="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!--!Font Awesome Free 6.5.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path d="M64 32C28.7 32 0 60.7 0 96V416c0 35.3 28.7 64 64 64H384c35.3 0 64-28.7 64-64V96c0-35.3-28.7-64-64-64H64zm64 192c17.7 0 32 14.3 32 32v96c0 17.7-14.3 32-32 32s-32-14.3-32-32V256c0-17.7 14.3-32 32-32zm64-64c0-17.7 14.3-32 32-32s32 14.3 32 32V352c0 17.7-14.3 32-32 32s-32-14.3-32-32V160zM320 288c17.7 0 32 14.3 32 32v32c0 17.7-14.3 32-32 32s-32-14.3-32-32V320c0-17.7 14.3-32 32-32z"/></svg>
|
After Width: | Height: | Size: 618 B |
35
index.html
Normal file
35
index.html
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
{{#restrict section="accounting" level="write" block=true}}{{/restrict}}
|
||||||
|
{{:admin_header title="Liste des scrutins"}}
|
||||||
|
|
||||||
|
<nav class="tabs">
|
||||||
|
<aside>
|
||||||
|
{{:linkbutton href="edit.html" label="Nouveau scrutin" shape="plus"}}
|
||||||
|
</aside>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
{{#list select="$$.name AS 'Scrutin'" order=1 desc=true}}
|
||||||
|
{{:assign var="qs" name=$name desc=$desc question=$question activity_see=$activity_see}}
|
||||||
|
{{:assign qs=$qs|http_build_query}}
|
||||||
|
{{:assign url="!voter/results.php?%s"|args:$qs}}
|
||||||
|
{{*Forbid visibility if not member of activity*}}
|
||||||
|
{{if $activity_see}}
|
||||||
|
{{#sql select="*" tables="services_users" where="id_service = :id_act AND id_user = :id_user" :id_act=$activity_see :id_user=$logged_user.id count="TRUE"}}
|
||||||
|
{{if !$count}}
|
||||||
|
{{:continue 2}}
|
||||||
|
{{/if}}
|
||||||
|
{{/sql}}
|
||||||
|
{{/if}}
|
||||||
|
<tr>
|
||||||
|
<th>{{$name}}</th>
|
||||||
|
<td class="actions">
|
||||||
|
{{:linkbutton href="result.html?id=%d"|args:$id label="Voir les résultats" shape="eye"}}
|
||||||
|
{{:linkbutton href="vote.html?id=%d"|args:$id label="Voter" shape="check"}}
|
||||||
|
{{:linkbutton href="edit.html?id=%d"|args:$id label="Modifier" shape="edit"}}
|
||||||
|
{{:linkbutton target="_dialog" href="delete.html?id=%d"|args:$id label="Supprimer" shape="delete"}}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{{else}}
|
||||||
|
<p class="alert block">
|
||||||
|
Aucun scrutin.
|
||||||
|
</p>
|
||||||
|
{{/list}}
|
8
module.ini
Normal file
8
module.ini
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
name = "Voter"
|
||||||
|
description = null
|
||||||
|
author = "Charlie, Mines de Rayons"
|
||||||
|
author_url = "https://www.minesderayons.fr"
|
||||||
|
restrict_section = null
|
||||||
|
restrict_level = "none"
|
||||||
|
menu = true
|
||||||
|
web = false
|
60
result.html
Normal file
60
result.html
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
{{:admin_header title="Résultats du vote"}}
|
||||||
|
|
||||||
|
{{if $_GET.id}}
|
||||||
|
{{#load assign="scrutin" id=$_GET.id|intval}}{{/load}}
|
||||||
|
|
||||||
|
<fieldset class"vote">
|
||||||
|
<legend>Question</legend>
|
||||||
|
<p class="vote-question">{{$scrutin.question}}</p>
|
||||||
|
|
||||||
|
{{:assign var=ids_oui value=[]}}
|
||||||
|
{{:assign var=ids_non value=[]}}
|
||||||
|
{{:assign var=ids_blancs value=[]}}
|
||||||
|
{{#users id=$scrutin.votes|keys}}
|
||||||
|
{{* On teste la condition de vote*}}
|
||||||
|
|
||||||
|
|
||||||
|
{{:assign var=vote from="scrutin.votes.%s"|args:$id}}
|
||||||
|
{{if $vote==-1}}
|
||||||
|
{{:assign var="ids_non." value=$id}}
|
||||||
|
{{elseif $vote==0}}
|
||||||
|
{{:assign var="ids_blanc." value=$id}}
|
||||||
|
{{elseif $vote==1}}
|
||||||
|
{{:assign var="ids_oui." value=$id}}
|
||||||
|
{{else}}
|
||||||
|
<p class="alert block">
|
||||||
|
Vote invalide détecté.
|
||||||
|
</p>
|
||||||
|
{{/if}}
|
||||||
|
{{/users}}
|
||||||
|
|
||||||
|
{{:assign var="nb_oui" value=$ids_oui|count}}
|
||||||
|
{{:assign var="nb_non" value=$ids_non|count}}
|
||||||
|
{{:assign var="nb_blanc" value=$ids_blanc|count|or:null}}
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<th> Oui </th>
|
||||||
|
<td> {{if $nb_oui}} {{$nb_oui}} {{else}} 0 {{/if}} </td>
|
||||||
|
<td> {{if $nb_oui}} (n° {{$ids_oui|implode:' ,'}}) {{/if}} </td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th> Non </th>
|
||||||
|
<td> {{if $nb_non}} {{$nb_non}} {{else}} 0 {{/if}} </td>
|
||||||
|
<td> {{if $nb_non}} (n° {{$ids_non|implode:' ,'}}) {{/if}} </td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th> Blanc </th>
|
||||||
|
<td> {{if $nb_blanc}} {{$nb_blanc}} {{else}} 0 {{/if}} </td>
|
||||||
|
<td> {{if $nb_blanc}} (n° {{$ids_blanc|implode:' ,'}}) {{/if}} </td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
{{:assign var=result value="round( 100*(%f-%f)/(%f+%f+%f), 2)"|math:$nb_oui:$nb_non:$nb_oui:$nb_non:$nb_blanc}}
|
||||||
|
<p>Résultat : {{$result}}%</p>
|
||||||
|
</fieldset>
|
||||||
|
{{:linkbutton href="./" label="Retour" shape="left"}}
|
||||||
|
|
||||||
|
{{else}}
|
||||||
|
<p class="alert block">
|
||||||
|
Aucun scrutin sélectionné. Il ne devrait y avoir aucune raison d'atterir sur cette page.
|
||||||
|
</p>
|
||||||
|
{{/if}}
|
27
scrutin.schema.json
Normal file
27
scrutin.schema.json
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"name": {
|
||||||
|
"description": "Nom du scrutin",
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"desc": {
|
||||||
|
"description": "Description",
|
||||||
|
"type": ["string", "null"]
|
||||||
|
},
|
||||||
|
"activity_see": {
|
||||||
|
"description": "Activité à laquelle il faut être inscrit pour voir le scrutin",
|
||||||
|
"type": ["integer", "null"]
|
||||||
|
},
|
||||||
|
"question": {
|
||||||
|
"description": "Question",
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"votes": {
|
||||||
|
"description": "Votes",
|
||||||
|
"type": ["array", "null"]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": ["name", "question"]
|
||||||
|
}
|
48
vote.html
Normal file
48
vote.html
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
{{:admin_header title="Voter"}}
|
||||||
|
|
||||||
|
{{if $_GET.id}}
|
||||||
|
{{#load assign="scrutin" id=$_GET.id|intval}}{{/load}}
|
||||||
|
|
||||||
|
{{:assign var="reponses" -1="Non" 0="" 1="Oui" }}
|
||||||
|
|
||||||
|
|
||||||
|
{{:assign user_id=$logged_user.id }}
|
||||||
|
Bonjour {{$logged_user.nom}}.
|
||||||
|
|
||||||
|
{{if $_POST.save}}
|
||||||
|
{{:assign var="scrutin.votes.%s"|args:$user_id value=$_POST.vote|intval}}
|
||||||
|
{{:save id=$scrutin.id
|
||||||
|
validate_schema="./scrutin.schema.json"
|
||||||
|
votes=$scrutin.votes
|
||||||
|
}}
|
||||||
|
|
||||||
|
{{:redirect to="./"}}
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
|
<form method="post" action="">
|
||||||
|
<fieldset class"vote">
|
||||||
|
<legend>Question</legend>
|
||||||
|
<p class="vote-question">{{$scrutin.question}}</p>
|
||||||
|
{{if $scrutin.votes|has_key:$user_id}}
|
||||||
|
{{:assign var="prev" from="scrutin.votes.%s"|args:$user_id}}
|
||||||
|
{{else}}
|
||||||
|
{{:assign var="prev" value=0}}
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
|
<dl>
|
||||||
|
{{:input type="select" required="false" shape="right" name="vote" label="Je vote :" options=$reponses default=$prev help=$scrutin.desc}}
|
||||||
|
</dl>
|
||||||
|
</fieldset>
|
||||||
|
|
||||||
|
|
||||||
|
<p class="submit">
|
||||||
|
{{:button type="submit" shape="right" label="Valider mon vote" name="save" class="main"}}
|
||||||
|
</p>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
|
||||||
|
{{else}}
|
||||||
|
<p class="alert block">
|
||||||
|
Aucun scrutin sélectionné. Il ne devrait y avoir aucune raison d'atterir sur cette page.
|
||||||
|
</p>
|
||||||
|
{{/if}}
|
Loading…
x
Reference in New Issue
Block a user