Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Stephane Crozat
apisub
Commits
74c47d7b
Commit
74c47d7b
authored
Mar 02, 2021
by
stph
Browse files
Add
#28
parent
4ad0ce19
Changes
6
Hide whitespace changes
Inline
Side-by-side
css/main.css
View file @
74c47d7b
...
...
@@ -30,18 +30,18 @@ hr {
font-size
:
150%
;
}
.sub
{
.sub
,
.valid
{
text-decoration
:
none
;
font-weight
:
bold
;
color
:
#
00612b
;
color
:
#
175e0c
;
}
.unsub
{
.unsub
,
.decline
{
text-decoration
:
none
;
font-weight
:
bold
;
color
:
#8e3c00
;
}
.valid
{
text-decoration
:
none
;
font-weight
:
bold
;
c
olor
:
#790600
;
.impossible
{
text-decoration
:
line-through
;
c
ursor
:
help
;
}
index.php
View file @
74c47d7b
...
...
@@ -22,7 +22,10 @@ if (isset($_GET['mode'])) {
if
(
$_GET
[
'mode'
]
==
'resp'
)
{
if
(
isset
(
$_GET
[
'action'
])
&&
isset
(
$_GET
[
'api'
])
&&
isset
(
$_GET
[
'login'
]))
{
if
(
$_GET
[
'action'
]
==
'validate'
)
{
$db
->
validate
(
$_SESSION
[
'utclogin'
],
$_GET
[
'api'
],
$_GET
[
'login'
]);
$db
->
validate
(
$_SESSION
[
'utclogin'
],
$_GET
[
'api'
],
$_GET
[
'login'
],
'TRUE'
);
}
elseif
(
$_GET
[
'action'
]
==
'decline'
)
{
$db
->
validate
(
$_SESSION
[
'utclogin'
],
$_GET
[
'api'
],
$_GET
[
'login'
],
'FALSE'
);
}
}
$view
->
respValidation
(
$db
->
apiListResp
(
$admin
,
$_SESSION
[
'utclogin'
]));
...
...
js/main.js
View file @
74c47d7b
document
.
querySelectorAll
(
'
.impossible
'
).
forEach
(
item
=>
{
item
.
addEventListener
(
'
click
'
,
event
=>
{
alert
(
'
Vous ne pouvez pas vous inscrire à cette Api :
\n
— le responsable de l
\'
Api a déjà décliné votre demande,
\n
— ou vous avez une autre Api validée la même semaine.
'
)
})
})
function
download_csv
(
students
)
{
var
csv
=
''
;
students
.
forEach
(
function
(
row
)
{
...
...
lib/db.php
View file @
74c47d7b
...
...
@@ -26,8 +26,17 @@ class DB {
}
public
function
apiList
(
$admin
,
$utclogin
)
{
$sql
=
'SELECT *, is_available(:utclogin, week, year) AS is_available
FROM vapi
$sql
=
'SELECT
a.*,
is_available(:utclogin, week, year) AS is_available,
CASE
WHEN s.api IS NULL THEN 0 /* student has not yet subscribed */
WHEN s.validation IS NULL THEN 0.5 /* student has subscribed and wait for valdiation */
WHEN s.validation THEN 1 /* student subscription has been validated */
ELSE -1 END AS validation /* student subscription has been declined or other subscription has been accepted the same week */
FROM vapi a
LEFT JOIN subscribe s
ON a.id = s.api
WHERE semester=:semester AND year=:year'
;
$st
=
$this
->
conn
->
prepare
(
$sql
);
$st
->
bindValue
(
':semester'
,
$admin
->
activeSemester
(),
PDO
::
PARAM_STR
);
...
...
@@ -148,42 +157,59 @@ class DB {
return
$res
;
}
public
function
validate
(
$resp
,
$api
,
$student
)
{
$today
=
date
(
'Ymd'
);
// Validation that $resp is resp of $api
// Validation that $resp is resp of $api
private
function
validateResp
(
$resp
,
$api
)
{
$sql
=
'SELECT COUNT(*) AS c FROM vapi WHERE resplogin=:resp AND id=:api'
;
$st
=
$this
->
conn
->
prepare
(
$sql
);
$st
->
bindValue
(
':resp'
,
$resp
,
PDO
::
PARAM_STR
);
$st
->
bindValue
(
':api'
,
$api
,
PDO
::
PARAM_STR
);
$st
->
execute
();
$res
=
$st
->
fetch
(
PDO
::
FETCH_ASSOC
);
if
(
$res
[
'c'
]
==
1
)
return
true
;
else
return
false
;
}
if
(
$res
[
'c'
]
==
1
)
{
/** This function either validate or decline a student participation to an Api.
** If $validation is true : student participation is unvalidated
** Else : student participation is declined
**/
public
function
validate
(
$resp
,
$api
,
$student
,
$validation
)
{
$today
=
date
(
'Ymd'
);
// Year and week calculation for Api
$sql
=
"SELECT year, week FROM vapi WHERE id=:api"
;
$st
=
$this
->
conn
->
prepare
(
$sql
);
$st
->
bindValue
(
':api'
,
$api
,
PDO
::
PARAM_STR
);
$st
->
execute
();
$res
=
$st
->
fetch
(
PDO
::
FETCH_ASSOC
);
$year
=
$res
[
'year'
];
$week
=
$res
[
'week'
];
// Check user is Api responsible
if
(
$this
->
validateResp
(
$resp
,
$api
)
==
false
)
{
echo
"<p>Erreur : le responsable
$resp
n'est pas autorisé à valider l'inscription de
$student
à l'Api
$api
</p>"
;
return
-
1
;
}
// Validate subscription
$st
=
$this
->
conn
->
prepare
(
$sql
);
$sql
=
"BEGIN"
;
$st
=
$this
->
conn
->
prepare
(
$sql
);
$st
->
execute
();
$sql
=
"UPDATE subscribe
SET validation='TRUE', validationdate=:today
WHERE api=:api AND utclogin=:utclogin"
;
$st
=
$this
->
conn
->
prepare
(
$sql
);
$st
->
bindValue
(
':utclogin'
,
$student
,
PDO
::
PARAM_STR
);
$st
->
bindValue
(
':api'
,
$api
,
PDO
::
PARAM_STR
);
$st
->
bindValue
(
':today'
,
$today
,
PDO
::
PARAM_STR
);
$res
=
$st
->
execute
();
// Year and week calculation for Api
$sql
=
"SELECT year, week FROM vapi WHERE id=:api"
;
$st
=
$this
->
conn
->
prepare
(
$sql
);
$st
->
bindValue
(
':api'
,
$api
,
PDO
::
PARAM_STR
);
$st
->
execute
();
$res
=
$st
->
fetch
(
PDO
::
FETCH_ASSOC
);
$year
=
$res
[
'year'
];
$week
=
$res
[
'week'
];
// Cancel other subscriptions the same week
// Validate subscription
$st
=
$this
->
conn
->
prepare
(
$sql
);
$sql
=
"BEGIN"
;
$st
=
$this
->
conn
->
prepare
(
$sql
);
$st
->
execute
();
$sql
=
"UPDATE subscribe
SET validation=:validation, validationdate=:today
WHERE api=:api AND utclogin=:utclogin"
;
$st
=
$this
->
conn
->
prepare
(
$sql
);
$st
->
bindValue
(
':utclogin'
,
$student
,
PDO
::
PARAM_STR
);
$st
->
bindValue
(
':api'
,
$api
,
PDO
::
PARAM_STR
);
$st
->
bindValue
(
':today'
,
$today
,
PDO
::
PARAM_STR
);
$st
->
bindValue
(
':validation'
,
$validation
,
PDO
::
PARAM_STR
);
$res
=
$st
->
execute
();
// Cancel other subscriptions the same week (if validation only)
if
(
$validation
==
'TRUE'
)
{
$sql
=
"UPDATE subscribe
SET validation='FALSE', validationdate=:today
WHERE api<>:api AND utclogin=:utclogin
...
...
@@ -195,16 +221,12 @@ class DB {
$st
->
bindValue
(
':year'
,
$year
,
PDO
::
PARAM_STR
);
$st
->
bindValue
(
':week'
,
$week
,
PDO
::
PARAM_STR
);
$res
=
$st
->
execute
();
$sql
=
"COMMIT"
;
$st
=
$this
->
conn
->
prepare
(
$sql
);
$st
->
execute
();
return
$res
;
}
else
{
echo
"<p>Erreur : le responsable
$resp
n'est pas autorisé à valider l'inscription de
$student
</p>"
;
// ajouter le nom de l'Api
return
-
1
;
}
$sql
=
"COMMIT"
;
$st
=
$this
->
conn
->
prepare
(
$sql
);
$st
->
execute
()
;
return
true
;
}
public
function
apiStudents
(
$utclogin
,
$api
)
{
...
...
lib/views.php
View file @
74c47d7b
...
...
@@ -24,6 +24,7 @@ class Views {
echo
'<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>'
;
echo
'<title>Api Sub</title>'
;
echo
'<link href="css/main.css" type="text/css" rel="stylesheet"/>'
;
echo
'<script src="js/main.js" defer></script>'
;
echo
'</head>'
;
echo
'<body>'
;
echo
'<h1>Foire aux Api '
.
$admin
->
activeSemester
()
.
$admin
->
activeYear
()
.
'</h1>'
;
...
...
@@ -114,27 +115,33 @@ class Views {
public
function
printApiList
(
$list
)
{
echo
'<hr/>'
;
if
(
$list
)
{
if
(
$list
)
{
echo
'<h2>Liste des Api</h2>'
;
$week
=
''
;
foreach
(
$list
as
$
row
)
{
if
(
$
row
[
'week'
]
!=
$week
)
{
$week
=
$
row
[
'week'
];
echo
"<h3>"
.
$this
->
printWeek
(
$
row
)
.
"</h3>"
;
foreach
(
$list
as
$
api
)
{
if
(
$
api
[
'week'
]
!=
$week
)
{
$week
=
$
api
[
'week'
];
echo
"<h3>"
.
$this
->
printWeek
(
$
api
)
.
"</h3>"
;
}
echo
'<p>'
;
if
(
$this
->
isActive
())
{
if
(
$
row
[
'open'
]
&&
$row
[
'is_available'
]
)
{
echo
"
<a href='index.php?action=sub&api=
$row[id]
' class='sub'>[inscription]</a>
"
;
if
(
$
api
[
'validation'
]
==
1
)
{
echo
"
[validé]
"
;
}
elseif
(
!
$row
[
'is_available'
])
{
echo
"[indisponible] "
;
elseif
(
$api
[
'validation'
]
==
0.5
)
{
echo
"[en attente] "
;
}
elseif
(
$api
[
'validation'
]
==
-
1
||
!
$api
[
'is_available'
])
{
echo
"[<span class='impossible'>indisponible</span>] "
;
}
elseif
(
!
$api
[
'open'
])
{
echo
"[<span class='impossible'>complet</span>] "
;
}
else
{
echo
'[complet] '
;
echo
"<a href='index.php?action=sub&api=
$api[id]
' class='sub'>[inscription]</a> "
;
}
}
echo
$this
->
printApi
(
$
row
);
echo
$this
->
printApi
(
$
api
);
echo
'</p>'
;
}
}
...
...
@@ -151,7 +158,7 @@ class Views {
echo
'<h2>Rappel</h2>'
;
echo
'<ul>'
;
echo
'<li>La validation d\'une inscription entraîne la confirmation de l\'ouverture de l\'Api.</li>'
;
echo
'<li>Toute inscription validée est irréversible.</li>'
;
echo
'<li>Toute inscription validée
ou déclinée
est irréversible.</li>'
;
echo
'</ul>'
;
if
(
$listsub
)
{
$api
=
''
;
...
...
@@ -168,7 +175,12 @@ class Views {
}
else
if
(
is_null
(
$sub
[
'validation'
]))
{
// At least one waiting subscription
echo
"<p> <a href='index.php?action=validate&api=
$sub[id]&login=$sub[utclogin]
&mode=resp' class='valid'>[valider]</a> "
.
$this
->
printStudent
(
$sub
)
.
" <span>Exclusivité :
$sub[indicator]
%</span></p>"
;
echo
"<p>
<a href='index.php?action=validate&api=
$sub[id]&login=$sub[utclogin]
&mode=resp' class='valid'>[valider]</a> "
.
$this
->
printStudent
(
$sub
)
.
" <span>Exclusivité :
$sub[indicator]
%</span>
<a href='index.php?action=decline&api=
$sub[id]&login=$sub[utclogin]
&mode=resp' class='decline'>[décliner]</a>
</p>"
;
}
else
{
// validation = FALSE lignes ignored
...
...
@@ -196,7 +208,6 @@ class Views {
$mailinglist
=
$mailinglist
.
"
$s[email]
,"
;
}
// Api CSV data (for JavaScript function)
echo
'<script src="js/main.js"></script>'
;
echo
"<script>var csvstudents = [['Nom','Prénom','Niveau','Mail','Login'],"
;
foreach
(
$students
as
$s
)
{
echo
"['
$s[surname]','$s[firstname]','$s[level]','$s[email]','$s[utclogin]']
,"
;
...
...
tmp/import/README.md
View file @
74c47d7b
...
...
@@ -29,7 +29,7 @@ INSERT INTO api (id,dbegin,code,name,description,duration,size,ects,resplogin) V
gen_random_uuid(),
TO_DATE('01/01/2020','DD/MM/YYYY'),
code,
'title,
'title
'
,
'longtitle',
duration,
size,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment