Skip to content
GitLab
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
57460f59
Commit
57460f59
authored
Jan 27, 2019
by
Stephane Crozat
Browse files
Gestion des validations fonctionnelle en base, à reporter en IHM
parent
93819d7f
Changes
7
Hide whitespace changes
Inline
Side-by-side
index.php
View file @
57460f59
...
...
@@ -41,27 +41,31 @@ $view->printUser($db->isResp($_SESSION['utclogin']), $db->isAdmin($_SESSION['utc
if
(
isset
(
$_GET
[
'mode'
]))
{
if
(
$_GET
[
'mode'
]
==
'resp'
)
{
$view
->
respValidation
(
$_SESSION
[
'utclogin'
]);
$view
->
respValidation
(
$db
->
apiListResp
(
$admin
,
$_SESSION
[
'utclogin'
]));
if
(
isset
(
$_GET
[
'action'
])
&&
isset
(
$_GET
[
'api'
])
&&
isset
(
$_GET
[
'login'
]))
{
if
(
$_GET
[
'action'
]
==
'validate'
)
{
$db
->
validate
(
$_SESSION
[
'utclogin'
],
$_GET
[
'api'
],
$_GET
[
'login'
]);
}
}
}
if
(
$_GET
[
'mode'
]
==
'admin'
)
{
$view
->
adminFunction
(
$_SESSION
[
'utclogin'
]);
}
}
/** Subscription and unsubscription management **/
if
(
isset
(
$_GET
[
'api'
])
&&
$admin
->
isActive
())
{
if
(
isset
(
$_GET
[
'action'
]))
{
if
(
$_GET
[
'action'
]
==
'sub'
)
{
$db
->
subToApi
(
$_SESSION
[
'utclogin'
],
$_GET
[
'api'
]);
}
elseif
(
$_GET
[
'action'
]
==
'unsub'
)
{
$db
->
unsubToApi
(
$_SESSION
[
'utclogin'
],
$_GET
[
'api'
]);
else
{
/** Subscription and unsubscription management **/
if
(
isset
(
$_GET
[
'api'
])
&&
$admin
->
isActive
())
{
if
(
isset
(
$_GET
[
'action'
]))
{
if
(
$_GET
[
'action'
]
==
'sub'
)
{
$db
->
subToApi
(
$_SESSION
[
'utclogin'
],
$_GET
[
'api'
]);
}
elseif
(
$_GET
[
'action'
]
==
'unsub'
)
{
$db
->
unsubToApi
(
$_SESSION
[
'utclogin'
],
$_GET
[
'api'
]);
}
}
}
$view
->
printInstructions
(
$db
->
config
());
$view
->
printSubList
(
$db
->
subList
(
$_SESSION
[
'utclogin'
]));
$view
->
printApiList
(
$db
->
apiList
(
$admin
));
}
$view
->
printInstructions
(
$db
->
config
());
$view
->
printSubList
(
$db
->
subList
(
$_SESSION
[
'utclogin'
]));
$view
->
printApiList
(
$db
->
apiList
(
'E'
,
2019
),
$_SESSION
[
'utclogin'
]);
?>
lib/admin.php
View file @
57460f59
<?php
const
IS_ACTIVE
=
true
;
class
Admin
{
...
...
@@ -13,4 +12,12 @@ class Admin {
return
$this
->
db
->
config
()[
'isactive'
];
}
public
function
activeSemester
()
{
return
'E'
;
}
public
function
activeYear
()
{
return
2019
;
}
}
lib/db.php
View file @
57460f59
...
...
@@ -24,13 +24,13 @@ class DB {
return
$res
;
}
public
function
apiList
(
$
semester
,
$year
)
{
public
function
apiList
(
$
admin
)
{
$sql
=
'SELECT *
FROM vapi
WHERE semester=:semester AND year=:year'
;
$st
=
$this
->
conn
->
prepare
(
$sql
);
$st
->
bindValue
(
':semester'
,
$
s
emester
,
PDO
::
PARAM_STR
);
$st
->
bindValue
(
':year'
,
$
y
ear
,
PDO
::
PARAM_INT
);
$st
->
bindValue
(
':semester'
,
$
admin
->
activeS
emester
()
,
PDO
::
PARAM_STR
);
$st
->
bindValue
(
':year'
,
$
admin
->
activeY
ear
()
,
PDO
::
PARAM_INT
);
$st
->
execute
();
$res
=
$st
->
fetchAll
(
PDO
::
FETCH_ASSOC
);
return
$res
;
...
...
@@ -105,4 +105,74 @@ class DB {
return
$res
[
'utclogin'
];
}
public
function
apiListResp
(
$admin
,
$utclogin
)
{
$sql
=
'SELECT *
FROM vsubscription
WHERE semester=:semester AND year=:year AND resplogin=:resp'
;
$st
=
$this
->
conn
->
prepare
(
$sql
);
$st
->
bindValue
(
':semester'
,
$admin
->
activeSemester
(),
PDO
::
PARAM_STR
);
$st
->
bindValue
(
':year'
,
$admin
->
activeYear
(),
PDO
::
PARAM_INT
);
$st
->
bindValue
(
':resp'
,
$utclogin
,
PDO
::
PARAM_STR
);
$st
->
execute
();
$res
=
$st
->
fetchAll
(
PDO
::
FETCH_ASSOC
);
return
$res
;
}
public
function
validate
(
$resp
,
$api
,
$student
)
{
$today
=
date
(
'Ymd'
);
// Validation that $resp is resp of $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
)
{
// 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'
];
// 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
();
// Cancel other subscriptions the same week
$sql
=
"UPDATE subscribe SET validation='FALSE', validationdate=:today
WHERE api<>:api AND utclogin=:utclogin
AND api IN (SELECT id FROM vapi WHERE week=:week AND year=:year)"
;
$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
(
':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
;
}
}
}
lib/views.php
View file @
57460f59
...
...
@@ -42,7 +42,10 @@ class Views {
echo
'<a href="index.php?mode=resp">[Gérer ses Api]</a> '
;
}
if
(
$isAdmin
)
{
echo
'<a href="index.php?mode=admin">[Super-pouvoirs]</a>'
;
echo
'<a href="index.php?mode=admin">[Super-pouvoirs]</a> '
;
}
if
(
$isResp
||
$isAdmin
)
{
echo
'<a href="index.php">[Accueil]</a>'
;
}
}
...
...
@@ -68,21 +71,6 @@ class Views {
}
}
public
function
printExplanation
(
$comment
,
$utclogin
)
{
if
(
$this
->
isActive
())
{
echo
'<h2>Commentaire</h2>'
;
echo
'<form method="get" action="index.php">'
;
echo
'<textarea name="explanation" cols="100" rows="5">'
.
$comment
.
'</textarea>'
;
echo
'<br/>'
;
echo
'<input type="submit" value="Enregistrer le commentaire"/>'
;
echo
'</form>'
;
}
else
{
echo
'<h2>Commentaire</h2>'
;
echo
'<p>'
.
$comment
.
'</p>'
;
}
}
public
function
printApiList
(
$list
)
{
if
(
$list
)
{
echo
'<h2>Liste des Api</h2>'
;
...
...
@@ -100,8 +88,21 @@ class Views {
}
}
public
function
respValidation
(
$utclogin
)
{
echo
"<p>Je dois vérifier que
$utclogin
est un responsable d'Api</p>"
;
public
function
respValidation
(
$listsub
)
{
echo
'<h1>Interface Responsable d\'Api</h2>'
;
if
(
$listsub
)
{
$api
=
''
;
foreach
(
$listsub
as
$sub
)
{
if
(
$api
!=
$sub
[
'id'
])
{
$api
=
$sub
[
'id'
];
echo
"<h2>
$sub[normcode]
$sub[name]
(Semaine
$sub[week]
)</h2>"
;
}
echo
"<p>
$sub[utclogin]
<a href='index.php?action=validate&api=
$sub[id]&login=$sub[utclogin]&mode=resp'>[valider]
</a></p>"
;
}
}
else
{
echo
"<p>Aucune Api à gérer</p>"
;
}
}
public
function
adminFunction
(
$utclogin
)
{
...
...
sql/apisub_dataset.sql
View file @
57460f59
...
...
@@ -16,11 +16,11 @@ INSERT INTO api VALUES (
);
INSERT
INTO
api
VALUES
(
'2afa8472-2178-11e9-b2b0-07511495b3b2'
,
TO_DATE
(
'2019012
8
'
,
'yyyymmdd'
),
2
,
'Cloud big data blockchain IA'
,
'At vero eos et accusamus'
,
3
,
12
,
1
,
'crozatst'
TO_DATE
(
'2019012
1
'
,
'yyyymmdd'
),
2
,
'Cloud big data blockchain IA'
,
'At vero eos et accusamus'
,
3
,
12
,
1
,
'crozatst'
);
INSERT
INTO
api
VALUES
(
'4352b3a0-217d-11e9-aabc-037b6e1a6a16'
,
TO_DATE
(
'2019012
1
'
,
'yyyymmdd'
),
3
,
'La TRM et la G1'
,
'Duis rhoncus turpis non libero auctor posuere.'
,
5
,
50
,
2
,
'
p
ro
f1
'
TO_DATE
(
'2019012
8
'
,
'yyyymmdd'
),
3
,
'La TRM et la G1'
,
'Duis rhoncus turpis non libero auctor posuere.'
,
5
,
50
,
2
,
'
c
ro
zatst
'
);
INSERT
INTO
subscribe
(
utclogin
,
api
,
subdate
)
VALUES
(
...
...
sql/apisub_tables.sql
View file @
57460f59
...
...
@@ -38,7 +38,8 @@ CREATE TABLE subscribe (
utclogin
TEXT
NOT
NULL
,
api
UUID
NOT
NULL
,
subdate
DATE
NOT
NULL
,
confirmed
BOOLEAN
NOT
NULL
DEFAULT
FALSE
,
validation
BOOLEAN
,
validationdate
DATE
,
FOREIGN
KEY
(
utclogin
)
REFERENCES
localuser
(
utclogin
),
FOREIGN
KEY
(
api
)
REFERENCES
api
(
id
),
PRIMARY
KEY
(
utclogin
,
api
)
...
...
sql/apisub_views.sql
View file @
57460f59
...
...
@@ -29,9 +29,10 @@ GROUP BY l.utclogin, u.surname, u.firstname;
CREATE
OR
REPLACE
VIEW
vsubscription
AS
SELECT
ap
.
*
,
TO_CHAR
(
su
.
subdate
,
'DD/MM/YYYY'
)
AS
subdate
,
su
.
utclogin
AS
sublogin
,
lo
.
*
lo
.
*
,
su
.
subdate
,
su
.
validation
,
su
.
validationdate
FROM
subscribe
su
JOIN
vapi
ap
ON
ap
.
id
=
su
.
api
LEFT
JOIN
vlocaluser
lo
ON
su
.
utclogin
=
lo
.
utclogin
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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