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
7a1cbc6f
Commit
7a1cbc6f
authored
Nov 16, 2018
by
Stephane Crozat
Browse files
Adding localcopy of users surname and lastname when then CAS login, in order to join CSV files'
parent
ccd05b52
Changes
3
Hide whitespace changes
Inline
Side-by-side
index.php
View file @
7a1cbc6f
...
...
@@ -18,14 +18,20 @@ if (!isset($_SESSION['ticket'])) {
$_SESSION
[
'surname'
]
=
strtoupper
(
$info
[
'cas:attributes'
][
'cas:sn'
]);
$_SESSION
[
'firstname'
]
=
$info
[
'cas:attributes'
][
'cas:givenName'
];
}
else
else
{
$cas
->
login
();
}
$_SESSION
[
'localcopy'
]
=
true
;
//call localcopy once per session
}
include
$_SERVER
[
'DOCUMENT_ROOT'
]
.
'/apisub/lib/db.php'
;
include
'lib/views.php'
;
$db
=
new
DB
();
if
(
$_SESSION
[
'localcopy'
])
{
$db
->
copyUser
(
$_SESSION
[
'utclogin'
],
$_SESSION
[
'surname'
],
$_SESSION
[
'firstname'
]);
$_SESSION
[
'localcopy'
]
=
false
;
}
Views
::
printHtmlBegin
();
Views
::
printUser
(
$_SESSION
[
'utclogin'
],
$_SESSION
[
'surname'
],
$_SESSION
[
'firstname'
]);
Views
::
printInstructions
();
...
...
lib/db.php
View file @
7a1cbc6f
...
...
@@ -55,4 +55,27 @@ class DB {
$res
=
$st
->
execute
();
return
$res
;
}
public
function
copyUser
(
$utclogin
,
$surname
,
$firstname
)
{
// Function used to create a local copy of surname and firstname of each user, in order to link to DFP files without utclogin
$sql
=
'SELECT utclogin FROM localuser WHERE utclogin=:utclogin'
;
$st1
=
$this
->
conn
->
prepare
(
$sql
);
$st1
->
bindValue
(
':utclogin'
,
$utclogin
,
PDO
::
PARAM_STR
);
$st1
->
execute
();
if
(
!
$st1
->
fetch
(
PDO
::
FETCH_ASSOC
))
{
// If user has never logged in yet, he is added to local copy
$sql
=
'INSERT INTO localuser(utclogin, firstname, surname) VALUES (:utclogin, :firstname, :surname)'
;
$st2
=
$this
->
conn
->
prepare
(
$sql
);
$st2
->
bindValue
(
':utclogin'
,
$utclogin
,
PDO
::
PARAM_STR
);
$st2
->
bindValue
(
':firstname'
,
$firstname
,
PDO
::
PARAM_STR
);
$st2
->
bindValue
(
':surname'
,
$surname
,
PDO
::
PARAM_STR
);
$res
=
$st2
->
execute
();
return
$res
;
}
else
{
return
0
;
};
}
}
sql/apisub.sql
View file @
7a1cbc6f
...
...
@@ -28,6 +28,12 @@ CREATE TABLE subscribe (
PRIMARY
KEY
(
utclogin
,
api
)
);
CREATE
TABLE
localuser
(
utclogin
TEXT
PRIMARY
KEY
,
surname
TEXT
,
firstname
TEXT
);
/** Test dataset
INSERT INTO api VALUES (
1,'Poésie et ingénierie',2019,'H',TO_DATE('20190121','yyyymmdd'),TO_DATE('20190125','yyyymmdd'),24,2,'stc@utc.fr'
...
...
@@ -40,17 +46,19 @@ INSERT INTO subscribe VALUES (
);
**/
CREATE
OR
REPLACE
VIEW
v
A
pi
AS
CREATE
OR
REPLACE
VIEW
v
a
pi
AS
SELECT
ap
.
code
,
CASE
WHEN
ap
.
code
<
10
THEN
'000'
||
ap
.
code
WHEN
ap
.
code
>=
10
THEN
'00'
||
ap
.
code
END
AS
normcode
,
ap
.
name
,
ap
.
year
,
ap
.
semester
,
TO_CHAR
(
ap
.
dbegin
,
'TMday FMDD TMmonth'
)
AS
dbegin
,
TO_CHAR
(
ap
.
dend
,
'TMday FMDD TMmonth'
)
AS
dend
,
ap
.
size
,
ap
.
ects
,
ap
.
mail
FROM
api
ap
ap
.
size
,
ap
.
ects
,
ap
.
mail
,
COUNT
(
su
.
utclogin
)
AS
nbsub
FROM
api
ap
LEFT
JOIN
subscribe
su
ON
ap
.
code
=
su
.
api
GROUP
BY
ap
.
code
,
normcode
,
ap
.
name
,
ap
.
year
,
ap
.
semester
,
dbegin
,
dend
,
ap
.
size
,
ap
.
ects
,
ap
.
mail
ORDER
BY
ap
.
year
,
ap
.
semester
,
ap
.
dbegin
,
ap
.
dend
,
ap
.
code
;
CREATE
OR
REPLACE
VIEW
v
S
ubscription
AS
CREATE
OR
REPLACE
VIEW
v
s
ubscription
AS
SELECT
ap
.
*
,
TO_CHAR
(
su
.
subdate
,
'DD/MM/YYYY'
)
AS
subdate
,
su
.
utclogin
FROM
subscribe
su
JOIN
vApi
ap
ON
ap
.
code
=
su
.
api
ORDER
BY
ap
.
year
,
ap
.
semester
,
ap
.
dbegin
,
ap
.
dend
,
ap
.
code
,
su
.
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